Class: EhbGameLib::Math::LineSegment
- Inherits:
-
Object
- Object
- EhbGameLib::Math::LineSegment
- Defined in:
- lib/ehb_game_lib/math/line_segment.rb
Instance Attribute Summary collapse
-
#p0 ⇒ Object
readonly
Returns the value of attribute p0.
-
#p1 ⇒ Object
readonly
Returns the value of attribute p1.
Instance Method Summary collapse
-
#initialize(x0, y0, x1, y1) ⇒ LineSegment
constructor
A new instance of LineSegment.
- #line ⇒ Object
- #point_in_area?(vector) ⇒ Boolean
Constructor Details
#initialize(x0, y0, x1, y1) ⇒ LineSegment
Returns a new instance of LineSegment.
8 9 10 11 |
# File 'lib/ehb_game_lib/math/line_segment.rb', line 8 def initialize(x0, y0, x1, y1) @p0 = Vector.new(x0, y0) @p1 = Vector.new(x1, y1) end |
Instance Attribute Details
#p0 ⇒ Object (readonly)
Returns the value of attribute p0.
6 7 8 |
# File 'lib/ehb_game_lib/math/line_segment.rb', line 6 def p0 @p0 end |
#p1 ⇒ Object (readonly)
Returns the value of attribute p1.
6 7 8 |
# File 'lib/ehb_game_lib/math/line_segment.rb', line 6 def p1 @p1 end |
Instance Method Details
#line ⇒ Object
13 14 15 |
# File 'lib/ehb_game_lib/math/line_segment.rb', line 13 def line @line ||= Line.new_by_coordinates(p0.x, p0.y, p1.x, p1.y) end |
#point_in_area?(vector) ⇒ Boolean
17 18 19 |
# File 'lib/ehb_game_lib/math/line_segment.rb', line 17 def point_in_area?(vector) x_interval.include?(vector.x) && y_interval.include?(vector.y) end |