Class: Ein::Vector
- Inherits:
-
Object
- Object
- Ein::Vector
- Defined in:
- lib/ein/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
- #*(scalar) ⇒ Object
-
#initialize(x, y) ⇒ Vector
constructor
A new instance of Vector.
- #length ⇒ Object
- #project(position) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Vector
Returns a new instance of Vector.
8 9 10 |
# File 'lib/ein/vector.rb', line 8 def initialize(x,y) @x, @y = x,y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/ein/vector.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/ein/vector.rb', line 6 def y @y end |
Instance Method Details
#*(scalar) ⇒ Object
20 21 22 23 |
# File 'lib/ein/vector.rb', line 20 def *(scalar) @x += @x * scalar @y += @y * scalar end |
#length ⇒ Object
16 17 18 |
# File 'lib/ein/vector.rb', line 16 def length Math.sqrt(@x**2 + @y**2) end |
#project(position) ⇒ Object
12 13 14 |
# File 'lib/ein/vector.rb', line 12 def project(position) Vector.new(@x * position.x, @y * position.y) end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/ein/vector.rb', line 25 def to_s "x: #@x, y: #@y" end |