Class: VectorBeWinding::Vector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/vector_be_winding/vector.rb', line 3

def x
  @x
end

#yObject

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

#normObject



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