Class: PointVector
- Inherits:
-
GeoVector
show all
- Includes:
- GeoCalc, PointOps, VectorOps
- Defined in:
- lib/geo_vectors/point_vector.rb,
lib/geo_vectors/point_vector/point_ops.rb,
lib/geo_vectors/point_vector/vector_ops.rb
Defined Under Namespace
Modules: PointOps, VectorOps
Instance Attribute Summary collapse
Attributes inherited from GeoVector
#unit
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PointOps
#add_to_point, #add_to_point!, #sub_from_point, #sub_from_point!
Methods included from VectorOps
#add, #add!, #random_vector, #sub, #sub!
Methods inherited from GeoVector
#/, #add, #add!, #scale, #sub, #sub!
Constructor Details
Returns a new instance of PointVector.
17
18
19
20
21
22
23
24
|
# File 'lib/geo_vectors/point_vector.rb', line 17
def initialize *args
if args[0].kind_of?(GeoPoint) && args.size == 1
@point = args[0]
else
args = normalize_points(args[0], args[1]) if args.only_kinds_of?(GeoPoint) && args.size == 2
@point = GeoPoint.new *args
end
end
|
Instance Attribute Details
#point ⇒ Object
Returns the value of attribute point.
14
15
16
|
# File 'lib/geo_vectors/point_vector.rb', line 14
def point
@point
end
|
Class Method Details
.origin ⇒ Object
26
27
28
|
# File 'lib/geo_vectors/point_vector.rb', line 26
def self.origin
[0, 0].geo_point
end
|
Instance Method Details
#bearing ⇒ Object
39
40
41
|
# File 'lib/geo_vectors/point_vector.rb', line 39
def bearing
origin.bearing_to(point).to_precision(2).to_f
end
|
#direction ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/geo_vectors/point_vector.rb', line 30
def direction
brng = bearing
begin
bearing_to_dir brng
rescue
brng
end
end
|
#distance(unit = :kms) ⇒ Object
51
52
53
|
# File 'lib/geo_vectors/point_vector.rb', line 51
def distance unit = :kms
origin.distance_to(point).send unit
end
|
#length(unit = :kms) ⇒ Object
47
48
49
|
# File 'lib/geo_vectors/point_vector.rb', line 47
def length unit = :kms
origin.distance_to(point)
end
|
#reverse ⇒ Object
64
65
66
|
# File 'lib/geo_vectors/point_vector.rb', line 64
def reverse
self.dup.reverse!
end
|
#reverse! ⇒ Object
68
69
70
71
|
# File 'lib/geo_vectors/point_vector.rb', line 68
def reverse!
self.point.reverse_point!
self
end
|
#scale!(scalar) ⇒ Object
58
59
60
61
62
|
# File 'lib/geo_vectors/point_vector.rb', line 58
def scale! scalar
self.lat = self.lat * scalar
self.lng = self.lng * scalar
self
end
|
#x ⇒ Object
55
|
# File 'lib/geo_vectors/point_vector.rb', line 55
def x; lng; end
|
#y ⇒ Object
56
|
# File 'lib/geo_vectors/point_vector.rb', line 56
def y; lat; end
|