Class: GeoMagic::MapPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_magic/map_point.rb

Direct Known Subclasses

Location, Point

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#distObject

Returns the value of attribute dist.



5
6
7
# File 'lib/geo_magic/map_point.rb', line 5

def dist
  @dist
end

#latitudeObject

Returns the value of attribute latitude.



5
6
7
# File 'lib/geo_magic/map_point.rb', line 5

def latitude
  @latitude
end

#longitudeObject

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

#within(distance) ⇒ Object



38
39
40
# File 'lib/geo_magic/map_point.rb', line 38

def within(distance) 
  GeoMagic::Radius.new self, distance
end