Class: DirectionVector
- Includes:
- GeoDirection, GeoDistance::Extract
- Defined in:
- lib/geo_vectors/direction_vector.rb
Instance Attribute Summary collapse
-
#direction ⇒ Object
direction symbol :N, :S, :SW, etc.
-
#distance ⇒ Object
GeoDistance object.
Instance Method Summary collapse
-
#add_to_point(point) ⇒ Object
return new point from adding vector to point.
-
#add_to_point!(point) ⇒ Object
add vector directly to point (destructive update).
- #as_bearing_vector ⇒ Object
- #as_point_vector ⇒ Object
-
#initialize(dist, dir) ⇒ DirectionVector
constructor
A new instance of DirectionVector.
- #random_vector ⇒ Object
- #scale!(scale) ⇒ Object
- #unit ⇒ Object
Methods included from GeoDirection
#bearing_to_dir, #dir_to_bearing, #directions, #get_valid_direction, #random_direction, #to_bearing_vector, #to_point_vector, #valid_direction?, #valid_directions
Methods included from GeoDistance::Extract
Methods inherited from GeoVector
#/, #add, #add!, #scale, #sub, #sub!
Constructor Details
#initialize(dist, dir) ⇒ DirectionVector
Returns a new instance of DirectionVector.
10 11 12 13 14 |
# File 'lib/geo_vectors/direction_vector.rb', line 10 def initialize dist, dir dist, dir = [dir, dist] if dir.kind_of? GeoDistance @distance = extract_distance dist @direction = get_valid_direction dir end |
Instance Attribute Details
#direction ⇒ Object
direction symbol :N, :S, :SW, etc.
7 8 9 |
# File 'lib/geo_vectors/direction_vector.rb', line 7 def direction @direction end |
#distance ⇒ Object
GeoDistance object
8 9 10 |
# File 'lib/geo_vectors/direction_vector.rb', line 8 def distance @distance end |
Instance Method Details
#add_to_point(point) ⇒ Object
return new point from adding vector to point
45 46 47 48 |
# File 'lib/geo_vectors/direction_vector.rb', line 45 def add_to_point point vec = as_bearing_vector point.destination_point vec.bearing, vec.distance.in_kms end |
#add_to_point!(point) ⇒ Object
add vector directly to point (destructive update)
51 52 53 54 55 56 57 |
# File 'lib/geo_vectors/direction_vector.rb', line 51 def add_to_point! point vec = as_bearing_vector dest = point.destination_point vec.bearing, vec.distance.in_kms point.lat = dest.lat point.lng = dest.lng point end |
#as_bearing_vector ⇒ Object
36 37 38 |
# File 'lib/geo_vectors/direction_vector.rb', line 36 def as_bearing_vector to_bearing_vector direction, distance end |
#as_point_vector ⇒ Object
40 41 42 |
# File 'lib/geo_vectors/direction_vector.rb', line 40 def as_point_vector to_point_vector direction, distance end |
#random_vector ⇒ Object
16 17 18 |
# File 'lib/geo_vectors/direction_vector.rb', line 16 def random_vector DirectionVector.new distance.random, random_direction end |
#scale!(scale) ⇒ Object
28 29 30 |
# File 'lib/geo_vectors/direction_vector.rb', line 28 def scale! scale @distance *= scale end |
#unit ⇒ Object
32 33 34 |
# File 'lib/geo_vectors/direction_vector.rb', line 32 def unit distance.unit end |