abscondment-rubyvor 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +56 -0
- data/Manifest.txt +30 -0
- data/README.txt +76 -0
- data/Rakefile +35 -0
- data/ext/Doc +30 -0
- data/ext/edgelist.c +204 -0
- data/ext/extconf.rb +3 -0
- data/ext/geometry.c +219 -0
- data/ext/heap.c +118 -0
- data/ext/memory.c +118 -0
- data/ext/output.c +251 -0
- data/ext/rb_cComputation.c +369 -0
- data/ext/rb_cPoint.c +35 -0
- data/ext/rb_cPriorityQueue.c +121 -0
- data/ext/ruby_vor_c.c +115 -0
- data/ext/ruby_vor_c.h +28 -0
- data/ext/vdefs.h +150 -0
- data/ext/voronoi.c +271 -0
- data/lib/ruby_vor.rb +16 -0
- data/lib/ruby_vor/computation.rb +137 -0
- data/lib/ruby_vor/geo_ruby_extensions.rb +15 -0
- data/lib/ruby_vor/point.rb +32 -0
- data/lib/ruby_vor/priority_queue.rb +84 -0
- data/lib/ruby_vor/version.rb +3 -0
- data/lib/ruby_vor/visualizer.rb +218 -0
- data/rubyvor.gemspec +36 -0
- data/test/test_computation.rb +354 -0
- data/test/test_point.rb +100 -0
- data/test/test_priority_queue.rb +129 -0
- data/test/test_voronoi_interface.rb +161 -0
- metadata +99 -0
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/ruby_vor'
|
4
|
+
|
5
|
+
class TestPriorityQueue < MiniTest::Unit::TestCase
|
6
|
+
|
7
|
+
def test_heap_order_property
|
8
|
+
# min heap by default
|
9
|
+
q = RubyVor::PriorityQueue.new
|
10
|
+
|
11
|
+
items = [1,2,3,4,5,6,99,4,-20,101,5412,2,-1,-1,-1,33.0,0,55,7,12321,123.123,-123.123,0,0,0]
|
12
|
+
items.each{|i| q.push(i)}
|
13
|
+
|
14
|
+
items.sort!
|
15
|
+
idx = 0
|
16
|
+
|
17
|
+
# Test peek
|
18
|
+
assert_equal q.peek.data, items[0]
|
19
|
+
|
20
|
+
while min = q.pop
|
21
|
+
# Test pop
|
22
|
+
assert_equal min.data, items[idx]
|
23
|
+
|
24
|
+
# Test peek
|
25
|
+
assert_equal q.peek.data, items[idx + 1] if idx + 1 < items.length
|
26
|
+
|
27
|
+
idx += 1
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_heapify
|
32
|
+
q = RubyVor::PriorityQueue.new
|
33
|
+
|
34
|
+
# Create a randomized data set.
|
35
|
+
#
|
36
|
+
# Not ideal for unit tests, since they *should* be done
|
37
|
+
# on static data so that failure/success is deterministic...
|
38
|
+
# but works for me.
|
39
|
+
|
40
|
+
100.times{ q.push(rand * 10000.0 - 5000.0)}
|
41
|
+
|
42
|
+
# Set things right.
|
43
|
+
q.heapify()
|
44
|
+
|
45
|
+
old_n = -1.0 * Float::MAX
|
46
|
+
while n = q.pop
|
47
|
+
assert n.priority >= old_n, 'Heap-order property violated'
|
48
|
+
old_n = n.priority
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_bad_data
|
53
|
+
q = RubyVor::PriorityQueue.new
|
54
|
+
10.times { q.push(rand * 100.0 - 50.0) }
|
55
|
+
|
56
|
+
#
|
57
|
+
# Heapify
|
58
|
+
#
|
59
|
+
old_data = q.data[1]
|
60
|
+
q.data[1] = 45
|
61
|
+
assert_raises TypeError do
|
62
|
+
q.heapify()
|
63
|
+
end
|
64
|
+
q.data[1] = old_data
|
65
|
+
assert_nothing_raised do
|
66
|
+
q.heapify()
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
#
|
71
|
+
# Percolation
|
72
|
+
#
|
73
|
+
[100, -100].each do |i|
|
74
|
+
assert_raises IndexError do
|
75
|
+
q.percolate_up(i)
|
76
|
+
end
|
77
|
+
assert_raises IndexError do
|
78
|
+
q.percolate_down(i)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
[:x, Class, nil, false].each do |i|
|
82
|
+
assert_raises TypeError do
|
83
|
+
q.percolate_up(i)
|
84
|
+
end
|
85
|
+
assert_raises TypeError do
|
86
|
+
q.percolate_down(i)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
[0,1,2,3].each do |i|
|
90
|
+
assert_nothing_raised do
|
91
|
+
q.percolate_up(i)
|
92
|
+
end
|
93
|
+
assert_nothing_raised do
|
94
|
+
q.percolate_down(i)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_build_queue
|
100
|
+
n = 100
|
101
|
+
|
102
|
+
q = RubyVor::PriorityQueue.build_queue(n) do |queue_item|
|
103
|
+
queue_item.priority = rand * 10000.0 - 5000.0
|
104
|
+
end
|
105
|
+
|
106
|
+
assert_equal n, q.data.length
|
107
|
+
assert_equal n, q.size
|
108
|
+
|
109
|
+
old_n = -1.0 * Float::MAX
|
110
|
+
while n = q.pop
|
111
|
+
assert n.priority >= old_n, 'Heap-order property violated'
|
112
|
+
old_n = n.priority
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
private
|
117
|
+
|
118
|
+
def assert_nothing_raised(&b)
|
119
|
+
begin
|
120
|
+
yield
|
121
|
+
rescue Exception => e
|
122
|
+
flunk "#{mu_pp(e)} exception encountered, expected no exceptions"
|
123
|
+
return
|
124
|
+
end
|
125
|
+
pass()
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
MiniTest::Unit.autorun
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'minitest/unit'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/ruby_vor'
|
4
|
+
|
5
|
+
|
6
|
+
class TestVoronoiInterface < MiniTest::Unit::TestCase
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
@points = @trianglulation_raw = @diagram_raw = nil
|
10
|
+
super(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
MAX_DELTA = 0.000001
|
15
|
+
|
16
|
+
def test_diagram_correct
|
17
|
+
# Perform the computation.
|
18
|
+
comp = RubyVor::VDDT::Computation.from_points(sample_points)
|
19
|
+
|
20
|
+
# Test each raw entry against three basic assertions:
|
21
|
+
# * entry lengths must match
|
22
|
+
# * entry types must match
|
23
|
+
# * entry values must match, with allowance for rounding errors (i.e. within a very small delta)
|
24
|
+
comp.voronoi_diagram_raw.each_with_index do |computed_entry, i|
|
25
|
+
sample_entry = example_diagram_raw[i]
|
26
|
+
|
27
|
+
|
28
|
+
assert_equal computed_entry.length, sample_entry.length
|
29
|
+
assert_equal computed_entry.first, sample_entry.first
|
30
|
+
|
31
|
+
computed_entry.each_with_index do |computed_value,j|
|
32
|
+
# We already tested the type...
|
33
|
+
next if j == 0
|
34
|
+
assert_in_delta computed_value, sample_entry[j], MAX_DELTA
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_triangulation_correct
|
41
|
+
# Perform the computation.
|
42
|
+
comp = RubyVor::VDDT::Computation.from_points(sample_points)
|
43
|
+
|
44
|
+
# One assertion:
|
45
|
+
# * raw triangulation must match exactly.
|
46
|
+
|
47
|
+
assert_equal example_triangulation_raw, comp.delaunay_triangulation_raw
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
#
|
53
|
+
# A few helper methods
|
54
|
+
#
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def sample_points
|
59
|
+
# Build a sample case
|
60
|
+
if @points.nil? || @points.empty?
|
61
|
+
@points = []
|
62
|
+
data = %w{ 0.0 0.0
|
63
|
+
0.0 0.5
|
64
|
+
0.5 0.0
|
65
|
+
3 3
|
66
|
+
0.5 0.5
|
67
|
+
5.0 5.0
|
68
|
+
5.0 5.5
|
69
|
+
5.5 5.0
|
70
|
+
5.5 5.5 }
|
71
|
+
for x in 0..(data.length/2 - 1)
|
72
|
+
@points << RubyVor::Point.new(data[x * 2].to_f, data[x * 2 + 1].to_f)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
@points
|
76
|
+
end
|
77
|
+
|
78
|
+
def example_diagram_raw
|
79
|
+
if @diagram_raw.nil? || @diagram_raw.empty?
|
80
|
+
@diagram_raw = [
|
81
|
+
[:s, 0.000000, 0.000000],
|
82
|
+
[:s, 0.500000, 0.000000],
|
83
|
+
[:l, 1.000000, 0.000000, 0.250000],
|
84
|
+
[:s, 0.000000, 0.500000],
|
85
|
+
[:l, 0.000000, 1.000000, 0.250000],
|
86
|
+
[:s, 0.500000, 0.500000],
|
87
|
+
[:l, 0.000000, 1.000000, 0.250000],
|
88
|
+
[:v, 0.250000, 0.250000],
|
89
|
+
[:l, 1.000000, 1.000000, 0.500000],
|
90
|
+
[:v, 0.250000, 0.250000],
|
91
|
+
[:e, 3, 1, 0],
|
92
|
+
[:l, 1.000000, 0.000000, 0.250000],
|
93
|
+
[:s, 3.000000, 3.000000],
|
94
|
+
[:l, 1.000000, 1.000000, 3.500000],
|
95
|
+
[:v, 3.250000, 0.250000],
|
96
|
+
[:e, 2, 0, 2],
|
97
|
+
[:l, 0.833333, 1.000000, 2.958333],
|
98
|
+
[:s, 5.000000, 5.000000],
|
99
|
+
[:l, 1.000000, 1.000000, 8.000000],
|
100
|
+
[:s, 5.500000, 5.000000],
|
101
|
+
[:l, 1.000000, 0.800000, 7.450000],
|
102
|
+
[:v, 5.249999, 2.750001],
|
103
|
+
[:l, 1.000000, 0.000000, 5.250000],
|
104
|
+
[:s, 5.000000, 5.500000],
|
105
|
+
[:l, 0.000000, 1.000000, 5.250000],
|
106
|
+
[:s, 5.500000, 5.500000],
|
107
|
+
[:l, 0.000000, 1.000000, 5.250000],
|
108
|
+
[:v, 5.250000, 5.250000],
|
109
|
+
[:e, 9, 4, 3],
|
110
|
+
[:l, 1.000000, 1.000000, 10.500000],
|
111
|
+
[:v, 5.250000, 5.250000],
|
112
|
+
[:e, 12, 5, 4],
|
113
|
+
[:l, 1.000000, 0.000000, 5.250000],
|
114
|
+
[:v, 0.250000, 3.250000],
|
115
|
+
[:e, 4, 6, 1],
|
116
|
+
[:e, 5, 6, 2],
|
117
|
+
[:l, 1.000000, 0.833333, 2.958333],
|
118
|
+
[:v, 2.750000, 5.250000],
|
119
|
+
[:e, 7, 7, 3],
|
120
|
+
[:e, 10, 7, 5],
|
121
|
+
[:l, 0.800000, 1.000000, 7.450000],
|
122
|
+
[:v, 15.249999, -9.749999],
|
123
|
+
[:e, 8, 3, 8],
|
124
|
+
[:e, 6, 2, 8],
|
125
|
+
[:l, 1.000000, 1.000000, 5.500000],
|
126
|
+
[:v, -9.749999, 15.249999],
|
127
|
+
[:e, 14, 9, 6],
|
128
|
+
[:e, 15, 9, 7],
|
129
|
+
[:l, 1.000000, 1.000000, 5.500000],
|
130
|
+
[:e, 1, -1, 1],
|
131
|
+
[:e, 17, -1, 9],
|
132
|
+
[:e, 13, -1, 5],
|
133
|
+
[:e, 11, 4, -1],
|
134
|
+
[:e, 16, 8, -1],
|
135
|
+
[:e, 0, 0, -1]
|
136
|
+
]
|
137
|
+
end
|
138
|
+
@diagram_raw
|
139
|
+
end
|
140
|
+
|
141
|
+
def example_triangulation_raw
|
142
|
+
if @trianglulation_raw.nil? || @trianglulation_raw.empty?
|
143
|
+
@trianglulation_raw = [
|
144
|
+
[0, 4, 2],
|
145
|
+
[1, 4, 0],
|
146
|
+
[3, 2, 4],
|
147
|
+
[5, 7, 3],
|
148
|
+
[5, 8, 7],
|
149
|
+
[6, 8, 5],
|
150
|
+
[1, 3, 4],
|
151
|
+
[3, 6, 5],
|
152
|
+
[7, 2, 3],
|
153
|
+
[1, 6, 3]
|
154
|
+
]
|
155
|
+
end
|
156
|
+
@trianglulation_raw
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
MiniTest::Unit.autorun
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: abscondment-rubyvor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brendan Ribera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.12.1
|
24
|
+
version:
|
25
|
+
description: 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.
|
26
|
+
email:
|
27
|
+
- brendan.ribera+rubyvor@gmail.com
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions:
|
31
|
+
- ext/extconf.rb
|
32
|
+
extra_rdoc_files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
- Rakefile
|
41
|
+
- ext/Doc
|
42
|
+
- ext/edgelist.c
|
43
|
+
- ext/extconf.rb
|
44
|
+
- ext/geometry.c
|
45
|
+
- ext/heap.c
|
46
|
+
- ext/memory.c
|
47
|
+
- ext/output.c
|
48
|
+
- ext/rb_cComputation.c
|
49
|
+
- ext/rb_cPoint.c
|
50
|
+
- ext/rb_cPriorityQueue.c
|
51
|
+
- ext/ruby_vor_c.c
|
52
|
+
- ext/ruby_vor_c.h
|
53
|
+
- ext/vdefs.h
|
54
|
+
- ext/voronoi.c
|
55
|
+
- lib/ruby_vor.rb
|
56
|
+
- lib/ruby_vor/computation.rb
|
57
|
+
- lib/ruby_vor/geo_ruby_extensions.rb
|
58
|
+
- lib/ruby_vor/point.rb
|
59
|
+
- lib/ruby_vor/priority_queue.rb
|
60
|
+
- lib/ruby_vor/version.rb
|
61
|
+
- lib/ruby_vor/visualizer.rb
|
62
|
+
- rubyvor.gemspec
|
63
|
+
- test/test_computation.rb
|
64
|
+
- test/test_point.rb
|
65
|
+
- test/test_priority_queue.rb
|
66
|
+
- test/test_voronoi_interface.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://github.com/bribera/rubyvor
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --main
|
72
|
+
- README.txt
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
- ext
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: "0"
|
87
|
+
version:
|
88
|
+
requirements: []
|
89
|
+
|
90
|
+
rubyforge_project: rubyvor
|
91
|
+
rubygems_version: 1.2.0
|
92
|
+
signing_key:
|
93
|
+
specification_version: 2
|
94
|
+
summary: RubyVor provides efficient computation of Voronoi diagrams and Delaunay triangulation for a set of Ruby points
|
95
|
+
test_files:
|
96
|
+
- test/test_priority_queue.rb
|
97
|
+
- test/test_voronoi_interface.rb
|
98
|
+
- test/test_point.rb
|
99
|
+
- test/test_computation.rb
|