Class: JustGo::Vector
- Inherits:
-
Struct
- Object
- Struct
- JustGo::Vector
- Defined in:
- lib/just_go/vector.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
Returns the value of attribute destination.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
Instance Attribute Details
#destination ⇒ Object
Returns the value of attribute destination
2 3 4 |
# File 'lib/just_go/vector.rb', line 2 def destination @destination end |
#origin ⇒ Object
Returns the value of attribute origin
2 3 4 |
# File 'lib/just_go/vector.rb', line 2 def origin @origin end |
Instance Method Details
#dx ⇒ Object
17 18 19 |
# File 'lib/just_go/vector.rb', line 17 def dx destination.x - origin.x end |
#dy ⇒ Object
21 22 23 |
# File 'lib/just_go/vector.rb', line 21 def dy destination.y - origin.y end |
#magnitude ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/just_go/vector.rb', line 3 def magnitude if dx.abs == 0 dy.abs elsif dy.abs == 0 dx.abs else nil end end |
#orthogonal? ⇒ Boolean
13 14 15 |
# File 'lib/just_go/vector.rb', line 13 def orthogonal? dx == 0 || dy == 0 end |