cacheable_kdtree 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +2 -2
- data/README.md +7 -7
- data/{kdtree.gemspec → cacheable_kdtree.gemspec} +3 -3
- data/lib/{kdtree → cacheable_kdtree}/latitude_longitude_node.rb +2 -2
- data/lib/{kdtree → cacheable_kdtree}/latitude_longitude_region.rb +1 -1
- data/lib/{kdtree → cacheable_kdtree}/latitude_longitude_tree.rb +11 -7
- data/lib/{kdtree → cacheable_kdtree}/util.rb +2 -2
- data/lib/cacheable_kdtree/version.rb +3 -0
- data/lib/{kdtree.rb → cacheable_kdtree.rb} +1 -1
- metadata +28 -28
- data/lib/kdtree/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjBjMDhmMThmNWNhODE5MWYxOTVjM2FmYThkZDE0MzU4M2NmMTAyNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDU2YjQwOTU5NTRhOTI4MDYzZTRmMjAwMTY2YTM4N2VjNjYzZTk4NA==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZGNkNTA5MzFmMWFhZWQwZjEyYmZjMmVmOTk4MWMwOGZlMmRmMjE1MWRiNzI2
|
10
|
+
NjZjM2UyNDgxMDdhMjE4ZjU1MzcwYTI1MTlmMDhjZmFhYjAxYjlhZDIyODZm
|
11
|
+
OWUzMGFjYjIwZDNmZWIwOTZkZjJmZWFkNDA0NjM3NjQ2MDhhZGY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZTk2OGRkYTdmZTJmZTdiNjcwZDU4YTRhNTA4NjVlYjgzYTc1YjkxNWY5YmY2
|
14
|
+
MDU4MmI2YWU2MWZhOWUwYjE1ZjYxNzcxMWNmZTEwOTM1NDhmZTM5NzBkMGI1
|
15
|
+
YzAwZDI1MmMxNmJjMTllNWY4YWRhNzBkMzQ3YjgwYmVmYzFmNTk=
|
data/.travis.yml
CHANGED
@@ -9,7 +9,7 @@ deploy:
|
|
9
9
|
provider: rubygems
|
10
10
|
api_key:
|
11
11
|
secure: TfNKvb7Qzqch5zzbaXv3Qv0m4amPSMQI8rlucf5nW2YxdNBIxGAx9sFeD495V592bzgcnYoeew5OFPOSxVd5YeT+VVu43cJv5gvI+Eouro7r4AKTuJjLcMRvmZvhy5RZrPhph1QwbDHbEcGTpqKcbXka8aURKgsnZzdsf66/iezp30/+q3gkWvUz94b4bBkcHMELsnwvlUX5XukVPP8Zh73YYzUy1Dh6UZiV/Reio2fQb+giSd1FafyptI5LXgmnNhnuLGwOajFgbEYr4ZFg8SfvlQ1SKZzHvH3tsFNUrCcsklowcbks/G/Hb/lOjZpqQH9M4BFrVwYNDEGN8pkmB6mBO56nK6JW4qJwh38MpAhhrLScy8IJw+D9tajkGMyjezb2svqWvMWQ6bdyBeeEsVF51oBqIXD/tadIAVY41ngCvcFw+zzi9568W27CL/9idFHi7rSB1Q/RLNIF2/uT0lt4eOk8Gr8Zyh/YImb3ktXSu4JwWQEfj4m+xugFXL1F/XkkOi/cSNq1tBf2J2LUCe+DxCogGWz5LbiY/aU1sfM4TJmp6awPP6JBv+qujJvVCJblKX/HIhIkfW0o1q1e639JYMTq/6DlIJQk+D9hXzY4X/lrsLlH7zYRie+HCxgxSg1tKTiZkfmohY3GOLLy8W/LfaR/ma622MLWjIIyUVM=
|
12
|
-
gem:
|
12
|
+
gem: cacheable_kdtree
|
13
13
|
on:
|
14
14
|
tags: true
|
15
|
-
repo: aaronFranssell/
|
15
|
+
repo: aaronFranssell/cacheable_kdtree
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/aaronFranssell/
|
2
|
-
[![Code Climate](https://codeclimate.com/github/aaronFranssell/
|
3
|
-
[![Test Coverage](https://codeclimate.com/github/aaronFranssell/
|
1
|
+
[![Build Status](https://travis-ci.org/aaronFranssell/cacheable_kdtree.svg?branch=master)](https://travis-ci.org/aaronFranssell/cacheable_kdtree)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/aaronFranssell/cacheable_kdtree/badges/gpa.svg)](https://codeclimate.com/github/aaronFranssell/cacheable_kdtree)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/aaronFranssell/cacheable_kdtree/badges/coverage.svg)](https://codeclimate.com/github/aaronFranssell/cacheable_kdtree/coverage)
|
4
4
|
|
5
5
|
# Kd-tree
|
6
6
|
|
@@ -19,13 +19,13 @@ gem 'cacheable_kdtree'
|
|
19
19
|
A Kd-tree is made up of multiple nodes. A single node contains the data associated with the latitude/longitude:
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
|
22
|
+
CacheableKdtree::LatitudeLongitudeNode.new(your_data_here, latitude_of_your_data, longitude_of_your_data)
|
23
23
|
```
|
24
24
|
|
25
25
|
Once you have an array of nodes, you can create a Kd-tree:
|
26
26
|
```ruby
|
27
|
-
nodes = [
|
28
|
-
my_tree =
|
27
|
+
nodes = [CacheableKdtree::LatitudeLongitudeNode.new(...), CacheableKdtree::LatitudeLongitudeNode.new(...)]
|
28
|
+
my_tree = CacheableKdtree::LatitudeLongitudeTree.new(nodes)
|
29
29
|
```
|
30
30
|
|
31
31
|
You can query your tree and return the closest nodes:
|
@@ -36,7 +36,7 @@ all_my_nodes = my_tree.closest(my_lat, my_long, distance, :kilometers)
|
|
36
36
|
|
37
37
|
## Contributing
|
38
38
|
|
39
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/aaronFranssell/
|
39
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/aaronFranssell/cacheable_kdtree.
|
40
40
|
|
41
41
|
Please make sure all tests pass and that [Rubocop](https://github.com/bbatsov/rubocop) is happy:
|
42
42
|
```ruby
|
@@ -1,16 +1,16 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'cacheable_kdtree/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'cacheable_kdtree'
|
8
|
-
spec.version =
|
8
|
+
spec.version = CacheableKdtree::VERSION
|
9
9
|
spec.authors = ['Aaron Franssell']
|
10
10
|
spec.email = ['aaron.franssell@gmail.com']
|
11
11
|
|
12
12
|
spec.summary = 'My implementation of a 2d k-d tree'
|
13
|
-
spec.homepage = 'https://github.com/aaronFranssell/
|
13
|
+
spec.homepage = 'https://github.com/aaronFranssell/cacheable_kdtree'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^(test|spec|features)/) }
|
16
16
|
spec.bindir = 'exe'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class CacheableKdtree::LatitudeLongitudeNode
|
2
2
|
attr_accessor :left, :right, :data, :latitude, :longitude, :region
|
3
3
|
|
4
4
|
def initialize(node_data, node_lat, node_long)
|
@@ -12,7 +12,7 @@ class Kdtree::LatitudeLongitudeNode
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.create_or_merge_regions(n1, n2)
|
15
|
-
return
|
15
|
+
return CacheableKdtree::LatitudeLongitudeRegion.new(n1.latitude, n1.longitude, n2.latitude, n2.longitude) if n1.region.nil? && n2.region.nil?
|
16
16
|
return n1.region.merge_point(n2.latitude, n2.longitude) if n1.region && n2.region.nil?
|
17
17
|
return n2.region.merge_point(n1.latitude, n1.longitude) if n2.region && n1.region.nil?
|
18
18
|
n1.region.merge_region(n2.region)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class CacheableKdtree::LatitudeLongitudeTree
|
2
2
|
attr_accessor :root
|
3
3
|
|
4
4
|
def initialize(node_list)
|
@@ -9,7 +9,11 @@ class Kdtree::LatitudeLongitudeTree
|
|
9
9
|
def closest(lat, long, distance, units = :miles)
|
10
10
|
fail 'Input must be numeric.' unless lat.is_a?(Numeric) && long.is_a?(Numeric) && distance.is_a?(Numeric)
|
11
11
|
fail 'Units must be either :kilometers or :miles.' unless %i(miles kilometers).include?(units)
|
12
|
-
bounding_box = units == :miles
|
12
|
+
bounding_box = if units == :miles
|
13
|
+
CacheableKdtree::Util.bounding_box_miles(lat, long, distance)
|
14
|
+
else
|
15
|
+
CacheableKdtree::Util.bounding_box_kilometers(lat, long, distance)
|
16
|
+
end
|
13
17
|
nearest_nodes(bounding_box)
|
14
18
|
end
|
15
19
|
|
@@ -26,15 +30,15 @@ class Kdtree::LatitudeLongitudeTree
|
|
26
30
|
def search_child?(child, bounding_box)
|
27
31
|
child &&
|
28
32
|
(bounding_box.point_in_region?(child.latitude, child.longitude) ||
|
29
|
-
(child.region &&
|
33
|
+
(child.region && CacheableKdtree::LatitudeLongitudeRegion.regions_intersect?(child.region, bounding_box)))
|
30
34
|
end
|
31
35
|
|
32
36
|
def find_regions(node)
|
33
37
|
return unless node
|
34
38
|
left_region = find_regions(node.left)
|
35
|
-
left_region =
|
39
|
+
left_region = CacheableKdtree::LatitudeLongitudeNode.create_or_merge_regions(node, node.left) if node.left
|
36
40
|
right_region = find_regions(node.right)
|
37
|
-
right_region =
|
41
|
+
right_region = CacheableKdtree::LatitudeLongitudeNode.create_or_merge_regions(node, node.right) if node.right
|
38
42
|
node.region = merge_regions(left_region, right_region)
|
39
43
|
node.region
|
40
44
|
end
|
@@ -48,8 +52,8 @@ class Kdtree::LatitudeLongitudeTree
|
|
48
52
|
def create_tree(node_list, depth = 0)
|
49
53
|
return if node_list.empty?
|
50
54
|
return node_list.first if node_list.length == 1
|
51
|
-
sorted_list =
|
52
|
-
lower_half, midpoint, greater_half =
|
55
|
+
sorted_list = CacheableKdtree::LatitudeLongitudeNode.sort_node_list(node_list, depth)
|
56
|
+
lower_half, midpoint, greater_half = CacheableKdtree::LatitudeLongitudeNode.partition_node_list(sorted_list)
|
53
57
|
midpoint.left = create_tree(lower_half, depth + 1)
|
54
58
|
midpoint.right = create_tree(greater_half, depth + 1)
|
55
59
|
midpoint
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class
|
1
|
+
class CacheableKdtree::Util
|
2
2
|
EARTH_MILES = 3959.0
|
3
3
|
EARTH_KILOMETERS = 6371.0
|
4
4
|
|
@@ -20,7 +20,7 @@ class Kdtree::Util
|
|
20
20
|
long_amount = radians_to_degrees(radius_distance / sphere_radius / Math.cos(degrees_to_radians(lat)))
|
21
21
|
long1 = long - long_amount
|
22
22
|
long2 = long + long_amount
|
23
|
-
|
23
|
+
CacheableKdtree::LatitudeLongitudeRegion.new(lat1, long1, lat2, long2)
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.degrees_to_radians(degrees)
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cacheable_kdtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Franssell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.10'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -70,42 +70,42 @@ dependencies:
|
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.10.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.10.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov-rcov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 0.2.3
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 0.2.3
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: mocha
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ~>
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: 1.1.0
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ~>
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 1.1.0
|
111
111
|
description:
|
@@ -115,22 +115,22 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
118
|
+
- .gitignore
|
119
|
+
- .rubocop.yml
|
120
|
+
- .travis.yml
|
121
121
|
- Gemfile
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
124
124
|
- bin/console
|
125
125
|
- bin/setup
|
126
|
-
-
|
127
|
-
- lib/
|
128
|
-
- lib/
|
129
|
-
- lib/
|
130
|
-
- lib/
|
131
|
-
- lib/
|
132
|
-
- lib/
|
133
|
-
homepage: https://github.com/aaronFranssell/
|
126
|
+
- cacheable_kdtree.gemspec
|
127
|
+
- lib/cacheable_kdtree.rb
|
128
|
+
- lib/cacheable_kdtree/latitude_longitude_node.rb
|
129
|
+
- lib/cacheable_kdtree/latitude_longitude_region.rb
|
130
|
+
- lib/cacheable_kdtree/latitude_longitude_tree.rb
|
131
|
+
- lib/cacheable_kdtree/util.rb
|
132
|
+
- lib/cacheable_kdtree/version.rb
|
133
|
+
homepage: https://github.com/aaronFranssell/cacheable_kdtree
|
134
134
|
licenses: []
|
135
135
|
metadata: {}
|
136
136
|
post_install_message:
|
@@ -139,17 +139,17 @@ require_paths:
|
|
139
139
|
- lib
|
140
140
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
|
-
- -
|
142
|
+
- - ! '>='
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
146
|
requirements:
|
147
|
-
- -
|
147
|
+
- - ! '>='
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
151
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.4.
|
152
|
+
rubygems_version: 2.4.5
|
153
153
|
signing_key:
|
154
154
|
specification_version: 4
|
155
155
|
summary: My implementation of a 2d k-d tree
|
data/lib/kdtree/version.rb
DELETED