Class: EhbGameLib::Math::Line
- Inherits:
-
Object
- Object
- EhbGameLib::Math::Line
- Defined in:
- lib/ehb_game_lib/math/line.rb
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#c ⇒ Object
readonly
Returns the value of attribute c.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(a, b, c) ⇒ Line
constructor
A new instance of Line.
- #point_in?(vector) ⇒ Boolean
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
#a ⇒ Object (readonly)
Returns the value of attribute a.
16 17 18 |
# File 'lib/ehb_game_lib/math/line.rb', line 16 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
16 17 18 |
# File 'lib/ehb_game_lib/math/line.rb', line 16 def b @b end |
#c ⇒ Object (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
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 |