Class: Ein::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/ein/vector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



6
7
8
# File 'lib/ein/vector.rb', line 6

def x
  @x
end

#yObject

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

#lengthObject



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_sObject



25
26
27
# File 'lib/ein/vector.rb', line 25

def to_s
  "x: #@x, y: #@y"
end