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.
15
16
17
18
19
20
21
22
|
# File 'lib/geo_vectors/point_vector.rb', line 15
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.
12
13
14
|
# File 'lib/geo_vectors/point_vector.rb', line 12
def point
@point
end
|
Class Method Details
.origin ⇒ Object
24
25
26
|
# File 'lib/geo_vectors/point_vector.rb', line 24
def self.origin
[0, 0].geo_point
end
|
Instance Method Details
#bearing ⇒ Object
37
38
39
|
# File 'lib/geo_vectors/point_vector.rb', line 37
def bearing
origin.bearing_to(point).to_precision(2).to_f
end
|
#direction ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/geo_vectors/point_vector.rb', line 28
def direction
brng = bearing
begin
bearing_to_dir brng
rescue
brng
end
end
|
#distance(unit = :kms) ⇒ Object
49
50
51
|
# File 'lib/geo_vectors/point_vector.rb', line 49
def distance unit = :kms
origin.distance_to(point).send unit
end
|
#length(unit = :kms) ⇒ Object
45
46
47
|
# File 'lib/geo_vectors/point_vector.rb', line 45
def length unit = :kms
origin.distance_to(point)
end
|
#reverse ⇒ Object
62
63
64
|
# File 'lib/geo_vectors/point_vector.rb', line 62
def reverse
self.dup.reverse!
end
|
#reverse! ⇒ Object
66
67
68
69
|
# File 'lib/geo_vectors/point_vector.rb', line 66
def reverse!
self.point.reverse_point!
self
end
|
#scale!(scalar) ⇒ Object
56
57
58
59
60
|
# File 'lib/geo_vectors/point_vector.rb', line 56
def scale! scalar
self.lat = self.lat * scalar
self.lng = self.lng * scalar
self
end
|
#x ⇒ Object
53
|
# File 'lib/geo_vectors/point_vector.rb', line 53
def x; lng; end
|
#y ⇒ Object
54
|
# File 'lib/geo_vectors/point_vector.rb', line 54
def y; lat; end
|