Class: GeoVector

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_vectors/geo_vector.rb,
lib/geo_vectors/macros.rb,
lib/geo_vectors/vector_parser.rb

Overview

A Vector consists of info that can transform a point into a destination point given some operation on that info

Direct Known Subclasses

BearingVector, DirectionVector, PointVector

Defined Under Namespace

Modules: Macros, Parser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGeoVector

Returns a new instance of GeoVector.



9
10
11
# File 'lib/geo_vectors/geo_vector.rb', line 9

def initialize
  @unit = :degrees
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



7
8
9
# File 'lib/geo_vectors/geo_vector.rb', line 7

def unit
  @unit
end

Instance Method Details

#/(scalar) ⇒ Object Also known as: reduce



50
51
52
# File 'lib/geo_vectors/geo_vector.rb', line 50

def / scalar
  scale (1.0 / scalar)
end

#add(vector) ⇒ Object Also known as: <<, +



29
30
31
# File 'lib/geo_vectors/geo_vector.rb', line 29

def add vector
  self.dup.add! vector
end

#add!(vector) ⇒ Object



13
14
15
# File 'lib/geo_vectors/geo_vector.rb', line 13

def add! vector
  raise '#add! method must be implemented by including class'
end

#directionObject



21
22
23
# File 'lib/geo_vectors/geo_vector.rb', line 21

def direction
  raise '#distance method must be implemented by including class'
end

#distanceObject



25
26
27
# File 'lib/geo_vectors/geo_vector.rb', line 25

def distance
  raise '#distance method must be implemented by including class'
end

#scale(scalar) ⇒ Object Also known as: *



45
46
47
# File 'lib/geo_vectors/geo_vector.rb', line 45

def scale scalar
  self.dup.scale! scalar
end

#scale!(scalar) ⇒ Object



17
18
19
# File 'lib/geo_vectors/geo_vector.rb', line 17

def scale! scalar
  raise '#scale! method must be implemented by including class'
end

#sub(vector) ⇒ Object Also known as: -



40
41
42
# File 'lib/geo_vectors/geo_vector.rb', line 40

def sub vector
  self.dup.sub vector
end

#sub!(vector) ⇒ Object



36
37
38
# File 'lib/geo_vectors/geo_vector.rb', line 36

def sub! vector
  add! vector.reverse
end