Class: JustGo::Vector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#destinationObject

Returns the value of attribute destination

Returns:

  • (Object)

    the current value of destination



2
3
4
# File 'lib/just_go/vector.rb', line 2

def destination
  @destination
end

#originObject

Returns the value of attribute origin

Returns:

  • (Object)

    the current value of origin



2
3
4
# File 'lib/just_go/vector.rb', line 2

def origin
  @origin
end

Instance Method Details

#dxObject



17
18
19
# File 'lib/just_go/vector.rb', line 17

def dx
  destination.x - origin.x
end

#dyObject



21
22
23
# File 'lib/just_go/vector.rb', line 21

def dy
  destination.y - origin.y
end

#magnitudeObject



3
4
5
6
7
8
9
10
11
# File 'lib/just_go/vector.rb', line 3

def magnitude
  if dx.abs == 0
    dy.abs
  elsif dy.abs == 0
    dx.abs
  else
    nil 
  end
end

#orthogonal?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/just_go/vector.rb', line 13

def orthogonal?
  dx == 0 || dy == 0
end