Class: CacheableKdtree::LatitudeLongitudeTree
- Inherits:
-
Object
- Object
- CacheableKdtree::LatitudeLongitudeTree
- Defined in:
- lib/cacheable_kdtree/latitude_longitude_tree.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #closest(lat, long, distance, units = :miles) ⇒ Object
-
#initialize(node_list) ⇒ LatitudeLongitudeTree
constructor
A new instance of LatitudeLongitudeTree.
Constructor Details
#initialize(node_list) ⇒ LatitudeLongitudeTree
Returns a new instance of LatitudeLongitudeTree.
4 5 6 7 |
# File 'lib/cacheable_kdtree/latitude_longitude_tree.rb', line 4 def initialize(node_list) @root = create_tree(node_list) find_regions(@root) end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_tree.rb', line 2 def root @root end |
Instance Method Details
#closest(lat, long, distance, units = :miles) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cacheable_kdtree/latitude_longitude_tree.rb', line 9 def closest(lat, long, distance, units = :miles) fail 'Input must be numeric.' unless lat.is_a?(Numeric) && long.is_a?(Numeric) && distance.is_a?(Numeric) fail 'Units must be either :kilometers or :miles.' unless %i(miles kilometers).include?(units) bounding_box = if units == :miles CacheableKdtree::Util.bounding_box_miles(lat, long, distance) else CacheableKdtree::Util.bounding_box_kilometers(lat, long, distance) end nearest_nodes(bounding_box) end |