Class: EhbGameLib::Math::LineSegment

Inherits:
Object
  • Object
show all
Defined in:
lib/ehb_game_lib/math/line_segment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#p0Object (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

#p1Object (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

#lineObject



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

Returns:

  • (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