Class: VectorBeWinding::Vector
- Inherits:
-
Object
- Object
- VectorBeWinding::Vector
- Defined in:
- lib/vector_be_winding/vector.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #*(s) ⇒ Object
- #+(v) ⇒ Object
- #-(v) ⇒ Object
- #-@ ⇒ Object
- #==(v) ⇒ Object
- #cross(v) ⇒ Object
- #dot(v) ⇒ Object
-
#initialize(x, y) ⇒ Vector
constructor
A new instance of Vector.
- #norm ⇒ Object
-
#reflect(v) ⇒ Object
Create reflection point of self.
Constructor Details
#initialize(x, y) ⇒ Vector
Returns a new instance of Vector.
5 6 7 8 |
# File 'lib/vector_be_winding/vector.rb', line 5 def initialize(x, y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
3 4 5 |
# File 'lib/vector_be_winding/vector.rb', line 3 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
3 4 5 |
# File 'lib/vector_be_winding/vector.rb', line 3 def y @y end |
Instance Method Details
#*(s) ⇒ Object
26 27 28 |
# File 'lib/vector_be_winding/vector.rb', line 26 def *(s) Vector.new(x * s, y * s) end |
#+(v) ⇒ Object
18 19 20 |
# File 'lib/vector_be_winding/vector.rb', line 18 def +(v) Vector.new(x + v.x, y + v.y) end |
#-(v) ⇒ Object
22 23 24 |
# File 'lib/vector_be_winding/vector.rb', line 22 def -(v) Vector.new(x - v.x, y - v.y) end |
#-@ ⇒ Object
14 15 16 |
# File 'lib/vector_be_winding/vector.rb', line 14 def -@() Vector.new(-x, -y) end |
#==(v) ⇒ Object
10 11 12 |
# File 'lib/vector_be_winding/vector.rb', line 10 def ==(v) x == v.x && y == v.y end |
#cross(v) ⇒ Object
38 39 40 |
# File 'lib/vector_be_winding/vector.rb', line 38 def cross(v) x * v.y - y * v.x end |
#dot(v) ⇒ Object
30 31 32 |
# File 'lib/vector_be_winding/vector.rb', line 30 def dot(v) x * v.x + y * v.y end |
#norm ⇒ Object
34 35 36 |
# File 'lib/vector_be_winding/vector.rb', line 34 def norm dot(self) end |
#reflect(v) ⇒ Object
Create reflection point of self
43 44 45 |
# File 'lib/vector_be_winding/vector.rb', line 43 def reflect(v) v + (v - self) end |