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.
16 17 18 19 20 |
# File 'lib/ehb_game_lib/math/line.rb', line 16 def initialize(a, b, c) @a = a @b = b @c = c end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
14 15 16 |
# File 'lib/ehb_game_lib/math/line.rb', line 14 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
14 15 16 |
# File 'lib/ehb_game_lib/math/line.rb', line 14 def b @b end |
#c ⇒ Object (readonly)
Returns the value of attribute c.
14 15 16 |
# File 'lib/ehb_game_lib/math/line.rb', line 14 def c @c end |
Class Method Details
.new_by_coordinates(x0, y0, x1, y1) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/ehb_game_lib/math/line.rb', line 5 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
22 23 24 |
# File 'lib/ehb_game_lib/math/line.rb', line 22 def point_in?(vector) (vector.x * a + vector.y * b + c).zero? end |