clumpy 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clumpy/builder.rb +4 -9
- data/lib/clumpy/cluster_behavior.rb +3 -4
- data/lib/clumpy/version.rb +1 -1
- data/spec/builder_spec.rb +1 -1
- data/spec/cluster_behavior_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba05344e6017c1ab80f749529bb6b1c3264b1e9f
|
4
|
+
data.tar.gz: f56e44bb1c4a19e0beb59afb8ab74476e0e7bec9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf0193a876462ba874e89549716e8b075fa76b0054041ce6d74b943790d54885d47a2de028d585ed7bc400f071269065acf379dfceeb49bc72fbfc1f8d5f160f
|
7
|
+
data.tar.gz: cc23d1a5f7cb5455d2d86e3f6649b3b99814858ae81976bce2f0d514b0fe5f182de82fa0f838474ea9d8c464076d0a9fd63f45605ef29e17b6254e0dbefa234b
|
data/lib/clumpy/builder.rb
CHANGED
@@ -8,7 +8,7 @@ module Clumpy
|
|
8
8
|
def initialize(points, options = {})
|
9
9
|
@points = points
|
10
10
|
@options = options || {}
|
11
|
-
@distance_modifier = options.fetch(:distance_modifier) {
|
11
|
+
@distance_modifier = options.fetch(:distance_modifier) { 16 }
|
12
12
|
@clusters = []
|
13
13
|
end
|
14
14
|
|
@@ -42,20 +42,15 @@ module Clumpy
|
|
42
42
|
clusters.find { |c| c.contains?(point) }
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
latitude_distance / @distance_modifier
|
47
|
-
end
|
48
|
-
|
49
|
-
def cluster_longitude_distance
|
50
|
-
longitude_distance / (@distance_modifier * 2)
|
45
|
+
def cluster_side_length
|
46
|
+
@cluster_size ||= (latitude_distance + longitude_distance) / @distance_modifier
|
51
47
|
end
|
52
48
|
|
53
49
|
def cluster_options
|
54
50
|
{
|
55
51
|
values_threshold: options[:values_threshold],
|
56
52
|
include_values: options[:include_values],
|
57
|
-
|
58
|
-
longitude_distance: cluster_longitude_distance
|
53
|
+
side_length: cluster_side_length
|
59
54
|
}
|
60
55
|
end
|
61
56
|
|
@@ -8,11 +8,10 @@ module Clumpy
|
|
8
8
|
@points = [point]
|
9
9
|
@options = options
|
10
10
|
|
11
|
-
|
12
|
-
lng_dist = options[:longitude_distance] || 10
|
11
|
+
side_length = options.fetch(:side_length) { 10 }
|
13
12
|
@bounds = OpenStruct.new(
|
14
|
-
latitude: (latitude -
|
15
|
-
longitude: (longitude -
|
13
|
+
latitude: (latitude - side_length)..(latitude + side_length),
|
14
|
+
longitude: (longitude - side_length)..(longitude + side_length)
|
16
15
|
)
|
17
16
|
end
|
18
17
|
|
data/lib/clumpy/version.rb
CHANGED
data/spec/builder_spec.rb
CHANGED
@@ -35,7 +35,7 @@ describe Clumpy::Builder do
|
|
35
35
|
|
36
36
|
it "passes the values threshold through to the cluster" do
|
37
37
|
builder = Clumpy::Builder.new([point1], values_threshold: 100, include_values: true)
|
38
|
-
builder.cluster_options.should eq({ values_threshold: 100, include_values: true,
|
38
|
+
builder.cluster_options.should eq({ values_threshold: 100, include_values: true, side_length: 33.128196875 })
|
39
39
|
clusters = builder.cluster
|
40
40
|
clusters.first.instance_variable_get(:@options).should eq builder.cluster_options
|
41
41
|
end
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Clumpy::ClusterBehavior do
|
4
4
|
let(:point) { OpenStruct.new(latitude: 15, longitude: 20) }
|
5
5
|
let(:other_point) { OpenStruct.new(latitude: 40, longitude: 40) }
|
6
|
-
let(:cluster) { Clumpy::Cluster.new(point,
|
6
|
+
let(:cluster) { Clumpy::Cluster.new(point, side_length: 10) }
|
7
7
|
|
8
8
|
it "has a nicish to_s representation" do
|
9
9
|
cluster.to_s.should include '# size: 1'
|