Module: GeoMagic::MapPoints
- Defined in:
- lib/geo_magic/util.rb
Constant Summary collapse
- RAD_PER_DEG =
0.017453293
Instance Method Summary collapse
- #rad ⇒ Object
- #the_closest(number, options = {}) ⇒ Object
- #within_distance(dist_obj, options = {:precision => :lowest}) ⇒ Object
- #within_rectangle(rectangle) ⇒ Object
Instance Method Details
#rad ⇒ Object
38 39 40 |
# File 'lib/geo_magic/util.rb', line 38 def rad {:km => 6371, :miles => 3956, :feet => 20895592, :meters => 6371000} end |
#the_closest(number, options = {}) ⇒ Object
68 69 70 71 72 |
# File 'lib/geo_magic/util.rb', line 68 def the_closest number, = {} calc_method = get_proc([:precision] || :normal) from_loc = get_location [:from] populate_distance(calc_method, from_loc).sort_by_distance[0..number] end |
#within_distance(dist_obj, options = {:precision => :lowest}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/geo_magic/util.rb', line 42 def within_distance dist_obj, = {:precision => :lowest} calc_method = get_proc([:precision] || :normal) from_loc = get_location get_dist_obj([:from]) dist = dist_obj.distance / (RAD_PER_DEG * rad[dist_obj.unit]) res = [] spots = populate_distance(calc_method, from_loc) spots.sort_by_distance.select do |item| it = get_dist_obj(item) if it.dist <= dist res << item else break end end res end |
#within_rectangle(rectangle) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/geo_magic/util.rb', line 61 def within_rectangle rectangle self.select do |point| obj = get_dist_obj(point) rectangle.overlaps? obj end end |