Module: Vector2d::Arithmetic
- Included in:
- Vector2d
- Defined in:
- lib/vector2d/arithmetic.rb
Overview
The operators. A scalar operand applies to both coordinates. Anything else is coerced into a vector and applied one axis at a time.
Instance Method Summary collapse
-
#*(other) ⇒ self
Multiplies vectors.
-
#+(other) ⇒ self
Adds vectors.
-
#+@ ⇒ self
Returns the vector unchanged.
-
#-(other) ⇒ self
Subtracts vectors.
-
#-@ ⇒ self
Returns the vector reversed.
-
#/(other) ⇒ self
Divides vectors.
-
#reverse ⇒ self
Reverses the vector.
Instance Method Details
#*(other) ⇒ self
15 16 17 |
# File 'lib/vector2d/arithmetic.rb', line 15 def *(other) calculate_each(:*, other) end |
#+(other) ⇒ self
37 38 39 |
# File 'lib/vector2d/arithmetic.rb', line 37 def +(other) calculate_each(:+, other) end |
#+@ ⇒ self
Returns the vector unchanged.
+Vector2d(2, 3) # => Vector2d(2,3)
66 67 68 |
# File 'lib/vector2d/arithmetic.rb', line 66 def +@ self end |
#-(other) ⇒ self
48 49 50 |
# File 'lib/vector2d/arithmetic.rb', line 48 def -(other) calculate_each(:-, other) end |
#-@ ⇒ self
Returns the vector reversed.
-Vector2d(2, 3) # => Vector2d(-2,-3)
57 58 59 |
# File 'lib/vector2d/arithmetic.rb', line 57 def -@ reverse end |
#/(other) ⇒ self
26 27 28 |
# File 'lib/vector2d/arithmetic.rb', line 26 def /(other) calculate_each(:/, other) end |
#reverse ⇒ self
Reverses the vector.
Vector2d(2, 3).reverse # => Vector2d(-2,-3)
75 76 77 |
# File 'lib/vector2d/arithmetic.rb', line 75 def reverse build(-x, -y) end |