class CTioga2::Graphics::Segment

Same as line, but with a beginning and an end

Attributes

x2[RW]
y2[RW]

Public Class Methods

new(x1, y1, x2, y2) click to toggle source
Calls superclass method CTioga2::Graphics::Line::new
# File lib/ctioga2/graphics/geometry.rb, line 68
def initialize(x1, y1, x2, y2)
  @x2 = x2
  @y2 = y2
  super(x1, y1, x2 - x1, y2 - y1)
end

Public Instance Methods

to_line() click to toggle source
# File lib/ctioga2/graphics/geometry.rb, line 89
def to_line()
  return Line.new(@x, @y, @dx, @dy)
end
within_bounds?(x, y) click to toggle source
# File lib/ctioga2/graphics/geometry.rb, line 75
def within_bounds?(x, y)
  return (
          (
           (x - @x) * (x - @x2) <= 0 or
           (x - @x).abs < 1e-15 or
           (x - @x2).abs < 1e-15
           ) and 
          ((y - @y) * (y - @y2) <= 0 or
           (y - @y).abs < 1e-15 or
           (y - @y2).abs < 1e-15
           )
          )
end