Class: BearingVector
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
#bearing ⇒ Object
Returns the value of attribute bearing.
7
8
9
|
# File 'lib/geo_vectors/bearing_vector.rb', line 7
def bearing
@bearing
end
|
#distance ⇒ Object
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
|
#direction ⇒ Object
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_vector ⇒ Object
25
26
27
|
# File 'lib/geo_vectors/bearing_vector.rb', line 25
def random_vector
BearingVector.new distance.random, random_bearing
end
|
#reverse ⇒ Object
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_s ⇒ Object
67
68
69
|
# File 'lib/geo_vectors/bearing_vector.rb', line 67
def to_s
"#{distance}, bearing: #{bearing} degrees"
end
|
#unit ⇒ Object
63
64
65
|
# File 'lib/geo_vectors/bearing_vector.rb', line 63
def unit
distance.unit
end
|