Class: EhbGameLib::Math::Line

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a, b, c) ⇒ Line

Returns a new instance of Line.



18
19
20
21
22
# File 'lib/ehb_game_lib/math/line.rb', line 18

def initialize(a, b, c)
  @a = a
  @b = b
  @c = c
end

Instance Attribute Details

#aObject (readonly)

Returns the value of attribute a.



16
17
18
# File 'lib/ehb_game_lib/math/line.rb', line 16

def a
  @a
end

#bObject (readonly)

Returns the value of attribute b.



16
17
18
# File 'lib/ehb_game_lib/math/line.rb', line 16

def b
  @b
end

#cObject (readonly)

Returns the value of attribute c.



16
17
18
# File 'lib/ehb_game_lib/math/line.rb', line 16

def c
  @c
end

Class Method Details

.new_by_coordinates(x0, y0, x1, y1) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/ehb_game_lib/math/line.rb', line 7

def new_by_coordinates(x0, y0, x1, y1)
  new(
    y1 - y0,
    x0 - x1,
    y0 * x1 + x0 * y0 - x0 * y1 - y0 * x0
  )
end

Instance Method Details

#point_in?(vector) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ehb_game_lib/math/line.rb', line 24

def point_in?(vector)
  (vector.x * a + vector.y * b + c).zero?
end