Class: BearingVector

Inherits:
GeoVector show all
Includes:
GeoDistance::Extract, GeoUnits::Converter
Defined in:
lib/geo_vectors/bearing_vector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GeoDistance::Extract

#extract_distance

Methods inherited from GeoVector

#/, #add, #add!, #scale, #sub, #sub!

Constructor Details

#initialize(dist, bearing) ⇒ BearingVector

should be Distance objects!



11
12
13
14
15
# File 'lib/geo_vectors/bearing_vector.rb', line 11

def initialize dist, bearing
  dist, bearing = [bearing, dist] if bearing.kind_of? GeoDistance
  self.bearing   = bearing
  self.distance  = dist
end

Instance Attribute Details

#bearingObject

Returns the value of attribute bearing.



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

def bearing
  @bearing
end

#distanceObject

Returns the value of attribute distance.



8
9
10
# File 'lib/geo_vectors/bearing_vector.rb', line 8

def distance
  @distance
end

Instance Method Details

#add_to_point(point) ⇒ Object



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

def add_to_point point
  self.dup.add_to_point! point 
end

#add_to_point!(point) ⇒ Object



29
30
31
32
33
34
# File 'lib/geo_vectors/bearing_vector.rb', line 29

def add_to_point! point
  dest_point = point.destination_point bearing, distance.in_kms
  point.lat = dest_point.lat
  point.lng = dest_point.lng
  point        
end

#directionObject



17
18
19
20
21
22
23
# File 'lib/geo_vectors/bearing_vector.rb', line 17

def direction
  begin
    bearing_to_dir bearing
  rescue
    bearing
  end
end

#random_vectorObject



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

def random_vector                             
  BearingVector.new distance.random, random_bearing
end

#reverseObject



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

def reverse
  self.dup.reverse!
end

#reverse!Object



54
55
56
57
# File 'lib/geo_vectors/bearing_vector.rb', line 54

def reverse!
  reverse_bearing! 
  self    
end

#scale!(scale) ⇒ Object



59
60
61
# File 'lib/geo_vectors/bearing_vector.rb', line 59

def scale! scale
  @distance = distance * scale 
end

#to_sObject



67
68
69
# File 'lib/geo_vectors/bearing_vector.rb', line 67

def to_s
  "#{distance}, bearing: #{bearing} degrees"
end

#unitObject



63
64
65
# File 'lib/geo_vectors/bearing_vector.rb', line 63

def unit
  distance.unit
end