hierclust 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +7 -0
- data/lib/hierclust/cluster.rb +8 -0
- data/lib/hierclust/point.rb +5 -0
- data/lib/hierclust/version.rb +1 -1
- data/spec/hierclust/cluster_spec.rb +13 -0
- data/spec/hierclust/point_spec.rb +4 -0
- metadata +2 -2
data/History.txt
CHANGED
data/lib/hierclust/cluster.rb
CHANGED
@@ -37,6 +37,14 @@ module Hierclust
|
|
37
37
|
@items.size
|
38
38
|
end
|
39
39
|
|
40
|
+
# Returns the distance from the center of this Cluster to the edge.
|
41
|
+
def radius
|
42
|
+
return nil if @items.empty?
|
43
|
+
return 0 if @items.size == 1
|
44
|
+
return (@items[0].distance_to(@items[1]) + @items[0].radius + @items[1].radius) / 2.0
|
45
|
+
raise "radius not implemented for clusters with more than two items"
|
46
|
+
end
|
47
|
+
|
40
48
|
# Returns a flat list of all the points contained in either this cluster
|
41
49
|
# or any of the clusters it contains.
|
42
50
|
def points
|
data/lib/hierclust/point.rb
CHANGED
@@ -23,6 +23,11 @@ module Hierclust
|
|
23
23
|
1
|
24
24
|
end
|
25
25
|
|
26
|
+
# Simplifies code by letting us treat Clusters and Points interchangeably
|
27
|
+
def radius #:nodoc:
|
28
|
+
0
|
29
|
+
end
|
30
|
+
|
26
31
|
# Simplifies code by letting us treat Clusters and Points interchangeably
|
27
32
|
def points #:nodoc:
|
28
33
|
[self]
|
data/lib/hierclust/version.rb
CHANGED
@@ -13,6 +13,10 @@ module Hierclust
|
|
13
13
|
it "should have nil y-coordinate" do
|
14
14
|
@c.y.should be_nil
|
15
15
|
end
|
16
|
+
|
17
|
+
it "should have nil radius" do
|
18
|
+
@c.radius.should be_nil
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
describe Cluster, " with one point" do
|
@@ -30,6 +34,10 @@ module Hierclust
|
|
30
34
|
it "should have the same y-coordinate as the point" do
|
31
35
|
@c.y.should == @p.y
|
32
36
|
end
|
37
|
+
|
38
|
+
it "should have 0 radius" do
|
39
|
+
@c.radius.should == 0
|
40
|
+
end
|
33
41
|
end
|
34
42
|
|
35
43
|
describe Cluster, " with two points" do
|
@@ -57,6 +65,11 @@ module Hierclust
|
|
57
65
|
it "should include both points" do
|
58
66
|
@points.should include(@p_1, @p_2)
|
59
67
|
end
|
68
|
+
|
69
|
+
it "should have correct radius" do
|
70
|
+
radius = Math.sqrt((@x_1 - @x_2) ** 2 + (@y_1 - @y_2) ** 2) / 2.0
|
71
|
+
@c.radius.should == radius
|
72
|
+
end
|
60
73
|
end
|
61
74
|
|
62
75
|
describe Cluster, " with one point and one cluster" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hierclust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandt Kurowski
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-03-21 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|