bribera-rubyvor 0.0.8 → 0.0.9
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/Manifest.txt +1 -0
- data/ext/rb_cComputation.c +36 -30
- data/lib/ruby_vor/version.rb +1 -1
- data/lib/ruby_vor/visualizer.rb +3 -3
- data/rubyvor.gemspec +4 -4
- data/test/test_point.rb +100 -0
- metadata +4 -2
data/Manifest.txt
CHANGED
data/ext/rb_cComputation.c
CHANGED
@@ -128,7 +128,8 @@ RubyVor_from_points(VALUE self, VALUE pointsArray)
|
|
128
128
|
VALUE
|
129
129
|
RubyVor_minimum_spanning_tree(int argc, VALUE *argv, VALUE self)
|
130
130
|
{
|
131
|
-
VALUE mst, dist_proc, nodes, nnGraph, points, queue, tmp, adjacent, adjacentData, adjacentDistance,
|
131
|
+
VALUE mst, dist_proc, nodes, nnGraph, points, queue, tmp, adjacent, adjacentData, adjacentDistance, current, currentData, floatMax;
|
132
|
+
ID i_call, i_push, i_pop, i_has_key;
|
132
133
|
long i;
|
133
134
|
|
134
135
|
/* 0 mandatory, 1 optional */
|
@@ -148,6 +149,12 @@ RubyVor_minimum_spanning_tree(int argc, VALUE *argv, VALUE self)
|
|
148
149
|
rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)", rb_obj_classname(dist_proc), rb_class2name(rb_cProc));
|
149
150
|
}
|
150
151
|
|
152
|
+
// Set up interned values
|
153
|
+
i_call = rb_intern("call");
|
154
|
+
i_push = rb_intern("push");
|
155
|
+
i_pop = rb_intern("pop");
|
156
|
+
i_has_key = rb_intern("has_key?");
|
157
|
+
|
151
158
|
points = rb_iv_get(self, "@points");
|
152
159
|
queue = rb_eval_string("RubyVor::PriorityQueue.new");
|
153
160
|
nnGraph = RubyVor_nn_graph(self);
|
@@ -166,46 +173,45 @@ RubyVor_minimum_spanning_tree(int argc, VALUE *argv, VALUE self)
|
|
166
173
|
/* 4: in_q */
|
167
174
|
rb_ary_push(tmp, Qtrue);
|
168
175
|
|
169
|
-
rb_funcall(queue,
|
176
|
+
rb_funcall(queue, i_push, 2, tmp, (i == 0) ? rb_float_new(0.0) : floatMax);
|
170
177
|
}
|
171
|
-
nodes = rb_obj_clone(
|
178
|
+
nodes = rb_obj_clone(rb_iv_get(queue, "@data"));
|
172
179
|
|
173
|
-
while(RTEST(
|
174
|
-
|
180
|
+
while(RTEST(current = rb_funcall(queue, i_pop, 0))) {
|
181
|
+
currentData = rb_iv_get(current, "@data");
|
175
182
|
|
176
183
|
/* mark in_q */
|
177
|
-
rb_ary_store(
|
184
|
+
rb_ary_store(currentData, 4, Qfalse);
|
178
185
|
|
179
186
|
/* check for presence of parent */
|
180
|
-
if (RTEST(RARRAY(
|
187
|
+
if (RTEST(RARRAY(currentData)->ptr[1])) {
|
181
188
|
/* push this node into adjacency_list of parent */
|
182
|
-
rb_ary_push(RARRAY(
|
189
|
+
rb_ary_push(RARRAY(rb_iv_get(RARRAY(currentData)->ptr[1], "@data"))->ptr[3], current);
|
183
190
|
/* push parent into adjacency_list of this node */
|
184
|
-
rb_ary_push(RARRAY(
|
191
|
+
rb_ary_push(RARRAY(currentData)->ptr[3], RARRAY(currentData)->ptr[1]);
|
185
192
|
}
|
186
193
|
|
187
|
-
for (i = 0; i < RARRAY(RARRAY(
|
194
|
+
for (i = 0; i < RARRAY(RARRAY(currentData)->ptr[2])->len; i++) {
|
188
195
|
/* grab indexed node */
|
189
|
-
adjacent = RARRAY(nodes)->ptr[FIX2LONG(RARRAY(RARRAY(
|
190
|
-
adjacentData =
|
196
|
+
adjacent = RARRAY(nodes)->ptr[FIX2LONG(RARRAY(RARRAY(currentData)->ptr[2])->ptr[i])];
|
197
|
+
adjacentData = rb_iv_get(adjacent, "@data");
|
191
198
|
|
192
199
|
/* check in_q -- only look at new nodes */
|
193
200
|
if (Qtrue == RARRAY(adjacentData)->ptr[4]) {
|
194
201
|
|
195
202
|
/* compare points by node -- adjacent against current */
|
196
|
-
adjacentDistance = rb_funcall(dist_proc,
|
197
|
-
|
198
|
-
RARRAY(points)->ptr[FIX2LONG(RARRAY(latestAdditionData)->ptr[0])],
|
203
|
+
adjacentDistance = rb_funcall(dist_proc, i_call, 2,
|
204
|
+
RARRAY(points)->ptr[FIX2LONG(RARRAY(currentData)->ptr[0])],
|
199
205
|
RARRAY(points)->ptr[FIX2LONG(RARRAY(adjacentData)->ptr[0])]);
|
200
206
|
|
201
207
|
/* If the new distance is better than our current priority, exchange them. */
|
202
|
-
if (RFLOAT(adjacentDistance)->value < RFLOAT(
|
208
|
+
if (RFLOAT(adjacentDistance)->value < RFLOAT(rb_iv_get(adjacent, "@priority"))->value) {
|
203
209
|
/* set new :parent */
|
204
|
-
rb_ary_store(adjacentData, 1,
|
210
|
+
rb_ary_store(adjacentData, 1, current);
|
205
211
|
/* update priority */
|
206
|
-
|
212
|
+
rb_iv_set(adjacent, "@priority", adjacentDistance);
|
207
213
|
/* percolate up into correctn position */
|
208
|
-
RubyVor_percolate_up(queue,
|
214
|
+
RubyVor_percolate_up(queue, rb_iv_get(adjacent, "@index"));
|
209
215
|
}
|
210
216
|
}
|
211
217
|
}
|
@@ -213,22 +219,22 @@ RubyVor_minimum_spanning_tree(int argc, VALUE *argv, VALUE self)
|
|
213
219
|
|
214
220
|
mst = rb_hash_new();
|
215
221
|
for (i = 0; i < RARRAY(nodes)->len; i++) {
|
216
|
-
|
217
|
-
|
218
|
-
if (!NIL_P(RARRAY(
|
219
|
-
adjacentData =
|
222
|
+
current = RARRAY(nodes)->ptr[i];
|
223
|
+
currentData = rb_iv_get(current, "@data");
|
224
|
+
if (!NIL_P(RARRAY(currentData)->ptr[1])) {
|
225
|
+
adjacentData = rb_iv_get(RARRAY(currentData)->ptr[1], "@data");
|
220
226
|
tmp = rb_ary_new2(2);
|
221
|
-
if (FIX2LONG(RARRAY(
|
222
|
-
rb_ary_push(tmp, RARRAY(
|
227
|
+
if (FIX2LONG(RARRAY(currentData)->ptr[0]) < FIX2LONG(RARRAY(adjacentData)->ptr[0])) {
|
228
|
+
rb_ary_push(tmp, RARRAY(currentData)->ptr[0]);
|
223
229
|
rb_ary_push(tmp, RARRAY(adjacentData)->ptr[0]);
|
224
230
|
} else {
|
225
231
|
rb_ary_push(tmp, RARRAY(adjacentData)->ptr[0]);
|
226
|
-
rb_ary_push(tmp, RARRAY(
|
227
|
-
}
|
228
|
-
if (!RTEST(rb_funcall(mst, rb_intern("has_key?"), 1, tmp))) {
|
229
|
-
rb_hash_aset(mst, tmp, rb_funcall(latestAddition, rb_intern("priority"), 0));
|
230
|
-
|
232
|
+
rb_ary_push(tmp, RARRAY(currentData)->ptr[0]);
|
231
233
|
}
|
234
|
+
|
235
|
+
/* if (!st_lookup(RHASH(mst)->tbl, tmp, 0)) { */
|
236
|
+
rb_hash_aset(mst, tmp, rb_iv_get(current, "@priority"));
|
237
|
+
/* } */
|
232
238
|
}
|
233
239
|
}
|
234
240
|
|
data/lib/ruby_vor/version.rb
CHANGED
data/lib/ruby_vor/visualizer.rb
CHANGED
@@ -2,7 +2,7 @@ require 'libxml'
|
|
2
2
|
module RubyVor
|
3
3
|
class Visualizer
|
4
4
|
|
5
|
-
COLORS = %w{black blue
|
5
|
+
COLORS = %w{black red blue lime gray yellow purple orange pink}
|
6
6
|
|
7
7
|
include LibXML
|
8
8
|
|
@@ -208,8 +208,8 @@ module RubyVor
|
|
208
208
|
|
209
209
|
def self.new_color
|
210
210
|
a = rand(256)
|
211
|
-
b = rand(256)
|
212
|
-
c = rand(256)
|
211
|
+
b = rand(256) | a
|
212
|
+
c = rand(256) ^ b
|
213
213
|
|
214
214
|
"rgb(#{[a,b,c].sort{|k,l| rand(3)-1}.join(',')})"
|
215
215
|
end
|
data/rubyvor.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rubyvor}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brendan Ribera"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2009-01-01}
|
10
10
|
s.description = %q{RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points. It is intended to function as a complemenet to GeoRuby. These structures can be used to compute a nearest-neighbor graph for a set of points. This graph can in turn be used for proximity-based clustering of the input points.}
|
11
11
|
s.email = ["brendan.ribera+rubyvor@gmail.com"]
|
12
12
|
s.extensions = ["ext/extconf.rb"]
|
13
13
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
14
|
-
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "ext/Doc", "ext/edgelist.c", "ext/extconf.rb", "ext/geometry.c", "ext/heap.c", "ext/memory.c", "ext/output.c", "ext/rb_cComputation.c", "ext/rb_cPoint.c", "ext/rb_cPriorityQueue.c", "ext/ruby_vor_c.c", "ext/ruby_vor_c.h", "ext/vdefs.h", "ext/voronoi.c", "lib/ruby_vor.rb", "lib/ruby_vor/computation.rb", "lib/ruby_vor/geo_ruby_extensions.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/priority_queue.rb", "lib/ruby_vor/version.rb", "lib/ruby_vor/visualizer.rb", "rubyvor.gemspec", "test/test_computation.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb"]
|
14
|
+
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "ext/Doc", "ext/edgelist.c", "ext/extconf.rb", "ext/geometry.c", "ext/heap.c", "ext/memory.c", "ext/output.c", "ext/rb_cComputation.c", "ext/rb_cPoint.c", "ext/rb_cPriorityQueue.c", "ext/ruby_vor_c.c", "ext/ruby_vor_c.h", "ext/vdefs.h", "ext/voronoi.c", "lib/ruby_vor.rb", "lib/ruby_vor/computation.rb", "lib/ruby_vor/geo_ruby_extensions.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/priority_queue.rb", "lib/ruby_vor/version.rb", "lib/ruby_vor/visualizer.rb", "rubyvor.gemspec", "test/test_computation.rb", "test/test_point.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb"]
|
15
15
|
s.has_rdoc = true
|
16
16
|
s.homepage = %q{http://github.com/bribera/rubyvor}
|
17
17
|
s.rdoc_options = ["--main", "README.txt"]
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.rubyforge_project = %q{rubyvor}
|
20
20
|
s.rubygems_version = %q{1.3.1}
|
21
21
|
s.summary = %q{RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points}
|
22
|
-
s.test_files = ["test/test_computation.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb"]
|
22
|
+
s.test_files = ["test/test_computation.rb", "test/test_priority_queue.rb", "test/test_voronoi_interface.rb", "test/test_point.rb"]
|
23
23
|
|
24
24
|
if s.respond_to? :specification_version then
|
25
25
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/test/test_point.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/ruby_vor'
|
4
|
+
|
5
|
+
class TestPoint < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
def test_instantiation
|
8
|
+
a = b = nil
|
9
|
+
|
10
|
+
assert_raises TypeError do
|
11
|
+
a = RubyVor::Point.new(:"10", 10)
|
12
|
+
end
|
13
|
+
|
14
|
+
assert_raises TypeError do
|
15
|
+
a = RubyVor::Point.new(10, :"10")
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_nothing_raised do
|
19
|
+
a = RubyVor::Point.new(123.456, 789.10)
|
20
|
+
b = RubyVor::Point.new("123.456", "789.10")
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal a, b
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_comparison
|
27
|
+
a = RubyVor::Point.new(10, 10)
|
28
|
+
b = RubyVor::Point.new(1, 1)
|
29
|
+
|
30
|
+
assert a > b
|
31
|
+
assert b < a
|
32
|
+
assert_equal -1, b <=> a
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_equality
|
36
|
+
a = RubyVor::Point.new(10, 10)
|
37
|
+
b = RubyVor::Point.new(10.0, 10)
|
38
|
+
c = RubyVor::Point.new(10.0, 10.0)
|
39
|
+
d = RubyVor::Point.new(10, 10.0)
|
40
|
+
|
41
|
+
z = RubyVor::Point.new(Math::PI, Math::PI)
|
42
|
+
o = a
|
43
|
+
|
44
|
+
|
45
|
+
# Test equality of values; both == and eql? perform this function.
|
46
|
+
assert a == a
|
47
|
+
assert a == b
|
48
|
+
assert a == c
|
49
|
+
assert a == d
|
50
|
+
assert a == o
|
51
|
+
assert a.eql?(a)
|
52
|
+
assert a.eql?(b)
|
53
|
+
assert a.eql?(c)
|
54
|
+
assert a.eql?(d)
|
55
|
+
assert a.eql?(o)
|
56
|
+
|
57
|
+
refute a == z
|
58
|
+
refute a.eql?(z)
|
59
|
+
|
60
|
+
|
61
|
+
# Test object equality.
|
62
|
+
refute a.equal?(b)
|
63
|
+
refute a.equal?(c)
|
64
|
+
refute a.equal?(d)
|
65
|
+
refute a.equal?(z)
|
66
|
+
|
67
|
+
assert a.equal?(a)
|
68
|
+
assert a.equal?(o)
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_hash
|
72
|
+
a = RubyVor::Point.new(10, 10)
|
73
|
+
b = RubyVor::Point.new(10.0, 10)
|
74
|
+
c = RubyVor::Point.new(10.0, 10.0)
|
75
|
+
d = RubyVor::Point.new(10, 10.0)
|
76
|
+
|
77
|
+
z = RubyVor::Point.new(Math::PI, Math::PI)
|
78
|
+
o = a
|
79
|
+
|
80
|
+
assert_equal a.hash, b.hash
|
81
|
+
assert_equal a.hash, c.hash
|
82
|
+
assert_equal a.hash, d.hash
|
83
|
+
assert_equal a.hash, o.hash
|
84
|
+
|
85
|
+
refute_equal a.hash, z.hash
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def assert_nothing_raised(&b)
|
91
|
+
begin
|
92
|
+
yield
|
93
|
+
rescue Exception => e
|
94
|
+
flunk "#{mu_pp(e)} exception encountered, expected no exceptions"
|
95
|
+
return
|
96
|
+
end
|
97
|
+
pass()
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bribera-rubyvor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendan Ribera
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-01 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/ruby_vor/visualizer.rb
|
61
61
|
- rubyvor.gemspec
|
62
62
|
- test/test_computation.rb
|
63
|
+
- test/test_point.rb
|
63
64
|
- test/test_priority_queue.rb
|
64
65
|
- test/test_voronoi_interface.rb
|
65
66
|
has_rdoc: true
|
@@ -94,3 +95,4 @@ test_files:
|
|
94
95
|
- test/test_computation.rb
|
95
96
|
- test/test_priority_queue.rb
|
96
97
|
- test/test_voronoi_interface.rb
|
98
|
+
- test/test_point.rb
|