Class: CTioga2::Graphics::Segment
- Defined in:
- lib/ctioga2/graphics/geometry.rb
Overview
Same as line, but with a beginning and an end
Instance Attribute Summary collapse
-
#x2 ⇒ Object
Returns the value of attribute x2.
-
#y2 ⇒ Object
Returns the value of attribute y2.
Attributes inherited from Line
Instance Method Summary collapse
-
#initialize(x1, y1, x2, y2) ⇒ Segment
constructor
A new instance of Segment.
- #to_line ⇒ Object
- #within_bounds?(x, y) ⇒ Boolean
Methods inherited from Line
Constructor Details
#initialize(x1, y1, x2, y2) ⇒ Segment
Returns a new instance of Segment.
68 69 70 71 72 |
# 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 |
Instance Attribute Details
#x2 ⇒ Object
Returns the value of attribute x2.
66 67 68 |
# File 'lib/ctioga2/graphics/geometry.rb', line 66 def x2 @x2 end |
#y2 ⇒ Object
Returns the value of attribute y2.
66 67 68 |
# File 'lib/ctioga2/graphics/geometry.rb', line 66 def y2 @y2 end |
Instance Method Details
#to_line ⇒ Object
89 90 91 |
# File 'lib/ctioga2/graphics/geometry.rb', line 89 def to_line() return Line.new(@x, @y, @dx, @dy) end |
#within_bounds?(x, y) ⇒ Boolean
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# 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 |