Class: GeoMagic::MapPoint
- Inherits:
-
Object
- Object
- GeoMagic::MapPoint
- Defined in:
- lib/geo_magic/map_point.rb
Instance Attribute Summary collapse
-
#dist ⇒ Object
Returns the value of attribute dist.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
Instance Method Summary collapse
-
#initialize(latitude, longitude) ⇒ MapPoint
constructor
A new instance of MapPoint.
- #move_distance(radius) ⇒ Object
- #move_within(distance) ⇒ Object
- #within(distance) ⇒ Object
Constructor Details
#initialize(latitude, longitude) ⇒ MapPoint
Returns a new instance of MapPoint.
7 8 9 10 |
# File 'lib/geo_magic/map_point.rb', line 7 def initialize latitude, longitude @latitude = latitude @longitude = longitude end |
Instance Attribute Details
#dist ⇒ Object
Returns the value of attribute dist.
5 6 7 |
# File 'lib/geo_magic/map_point.rb', line 5 def dist @dist end |
#latitude ⇒ Object
Returns the value of attribute latitude.
5 6 7 |
# File 'lib/geo_magic/map_point.rb', line 5 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
5 6 7 |
# File 'lib/geo_magic/map_point.rb', line 5 def longitude @longitude end |
Instance Method Details
#move_distance(radius) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/geo_magic/map_point.rb', line 25 def move_distance radius distance = radius.distance conversion = GeoDistance.radians_ratio(distance.unit) max_radius_rad = distance.distance / conversion range = (max_radius_rad * normalize).to_i dlong = (get_random_radiant(range) / normalize) * conversion dlat = (get_random_radiant(range) / normalize) * conversion GeoMagic::Point.new dist.latitude + dlat, dist.longitude + dlong end |
#move_within(distance) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/geo_magic/map_point.rb', line 12 def move_within distance conversion = GeoDistance.radians_ratio(distance.unit) max_radius_rad = dist.distance range = (max_radius_rad * normalize).to_i dlong = (get_random_radiant(range) / normalize) dlat = (get_random_radiant(range) / normalize) @latitude += dlat @longitude += dlong end |