Class: CacheableKdtree::LatitudeLongitudeNode
- Inherits:
-
Object
- Object
- CacheableKdtree::LatitudeLongitudeNode
- Defined in:
- lib/cacheable_kdtree/latitude_longitude_node.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#left ⇒ Object
Returns the value of attribute left.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#region ⇒ Object
Returns the value of attribute region.
-
#right ⇒ Object
Returns the value of attribute right.
Class Method Summary collapse
- .create_or_merge_regions(n1, n2) ⇒ Object
- .partition_node_list(node_list) ⇒ Object
- .sort_by_distance_between(lat, long, node_list) ⇒ Object
- .sort_node_list(node_list, depth) ⇒ Object
- .use_latitude?(depth) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(node_data, node_lat, node_long) ⇒ LatitudeLongitudeNode
constructor
A new instance of LatitudeLongitudeNode.
- #to_s ⇒ Object
Constructor Details
#initialize(node_data, node_lat, node_long) ⇒ LatitudeLongitudeNode
Returns a new instance of LatitudeLongitudeNode.
4 5 6 7 8 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 4 def initialize(node_data, node_lat, node_long) @data = node_data @latitude = node_lat @longitude = node_long end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def data @data end |
#latitude ⇒ Object
Returns the value of attribute latitude.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def latitude @latitude end |
#left ⇒ Object
Returns the value of attribute left.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def left @left end |
#longitude ⇒ Object
Returns the value of attribute longitude.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def longitude @longitude end |
#region ⇒ Object
Returns the value of attribute region.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def region @region end |
#right ⇒ Object
Returns the value of attribute right.
2 3 4 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 2 def right @right end |
Class Method Details
.create_or_merge_regions(n1, n2) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 20 def self.create_or_merge_regions(n1, n2) return CacheableKdtree::LatitudeLongitudeRegion.new(n1.latitude, n1.longitude, n2.latitude, n2.longitude) if n1.region.nil? && n2.region.nil? return n1.region.merge_point(n2.latitude, n2.longitude) if n1.region && n2.region.nil? return n2.region.merge_point(n1.latitude, n1.longitude) if n2.region && n1.region.nil? n1.region.merge_region(n2.region) end |
.partition_node_list(node_list) ⇒ Object
31 32 33 34 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 31 def self.partition_node_list(node_list) midpoint = node_list.length / 2 [node_list.slice(0, node_list.length / 2), node_list[midpoint], node_list.slice(midpoint + 1..-1)] end |
.sort_by_distance_between(lat, long, node_list) ⇒ Object
14 15 16 17 18 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 14 def self.sort_by_distance_between(lat, long, node_list) node_list.sort_by do |node| CacheableKdtree::Util.distance_miles(lat, long, node.latitude, node.longitude) end end |
.sort_node_list(node_list, depth) ⇒ Object
27 28 29 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 27 def self.sort_node_list(node_list, depth) use_latitude?(depth) ? node_list.sort_by(&:latitude) : node_list.sort_by(&:longitude) end |
.use_latitude?(depth) ⇒ Boolean
36 37 38 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 36 def self.use_latitude?(depth) depth.even? end |
Instance Method Details
#to_s ⇒ Object
10 11 12 |
# File 'lib/cacheable_kdtree/latitude_longitude_node.rb', line 10 def to_s "region: #{region ? region.to_s : region}" end |