bribera-rubyvor 0.0.2 → 0.0.3
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 +4 -0
- data/Manifest.txt +1 -1
- data/ext/memory.c +18 -20
- data/ext/vdefs.h +1 -1
- data/ext/voronoi.c +41 -40
- data/ext/voronoi_interface.c +19 -15
- data/lib/ruby_vor/computation.rb +28 -0
- data/lib/ruby_vor/point.rb +2 -12
- data/lib/ruby_vor/version.rb +1 -1
- data/lib/ruby_vor.rb +6 -6
- data/rubyvor.gemspec +2 -2
- data/test/test_voronoi_interface.rb +6 -6
- metadata +2 -2
- data/lib/ruby_vor/decomposition.rb +0 -22
data/History.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
=== 0.0.3 / 2008-12-03
|
2
|
+
|
3
|
+
* Fixed a segfault by using rb_ary_push instead of direct pointer manipulation. Much simpler.
|
4
|
+
|
1
5
|
=== 0.0.2 / 2008-12-03
|
2
6
|
|
3
7
|
* Computations succeed on a naive Point class, returning raw values for the associated Voronoi Diagram and Delaunay triangulation.
|
data/Manifest.txt
CHANGED
data/ext/memory.c
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
|
2
2
|
/*** MEMORY.C ***/
|
3
3
|
|
4
|
+
#include <ruby.h>
|
4
5
|
#include <stdio.h>
|
5
|
-
#include <stdlib.h> /* malloc()
|
6
|
+
#include <stdlib.h> /* malloc() */
|
6
7
|
|
7
8
|
#include "vdefs.h"
|
8
9
|
|
@@ -61,17 +62,15 @@ update_memory_map(char * newp)
|
|
61
62
|
char *
|
62
63
|
myalloc(unsigned n)
|
63
64
|
{
|
64
|
-
char * t
|
65
|
+
char * t;
|
66
|
+
|
65
67
|
if ((t=(char*)malloc(n)) == (char *) 0)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
exit(0) ;
|
70
|
-
}
|
71
|
-
total_alloc += n ;
|
68
|
+
rb_raise(rb_eNoMemError, "Insufficient memory processing site %d (%d bytes in use)\n", rubyvorState.siteidx, total_alloc);
|
69
|
+
|
70
|
+
total_alloc += n;
|
72
71
|
|
73
72
|
update_memory_map(t);
|
74
|
-
return (t)
|
73
|
+
return (t);
|
75
74
|
}
|
76
75
|
|
77
76
|
char *
|
@@ -81,24 +80,25 @@ myrealloc(void * oldp, unsigned n, unsigned oldn)
|
|
81
80
|
int i;
|
82
81
|
|
83
82
|
if ((newp=(char*)realloc(oldp, n)) == (char *) 0)
|
84
|
-
|
85
|
-
fprintf(stderr,"Insufficient memory processing site %d (%d bytes in use)\n",
|
86
|
-
rubyvorState.siteidx, total_alloc) ;
|
87
|
-
exit(0) ;
|
88
|
-
}
|
83
|
+
rb_raise(rb_eNoMemError, "Insufficient memory processing site %d (%d bytes in use)\n", rubyvorState.siteidx, total_alloc);
|
89
84
|
|
90
|
-
total_alloc += (n - oldn)
|
85
|
+
total_alloc += (n - oldn);
|
91
86
|
|
92
87
|
update_memory_map(newp);
|
93
88
|
|
94
89
|
// Mark oldp as freed, since free() was called by realloc.
|
95
|
-
|
96
|
-
|
90
|
+
//
|
91
|
+
// TODO: this seems naive; measure if this is a bottleneck & use a hash table or some other scheme if it is.
|
92
|
+
for (i=0; i<nallocs; i++)
|
93
|
+
{
|
94
|
+
if (memory_map[i] != (char*)0 && memory_map[i] == oldp)
|
95
|
+
{
|
97
96
|
memory_map[i] = (char*)0;
|
98
97
|
break;
|
99
98
|
}
|
100
99
|
}
|
101
|
-
|
100
|
+
|
101
|
+
return (newp);
|
102
102
|
}
|
103
103
|
|
104
104
|
|
@@ -115,6 +115,4 @@ void free_all(void)
|
|
115
115
|
}
|
116
116
|
free(memory_map);
|
117
117
|
nallocs = 0;
|
118
|
-
|
119
|
-
debug_memory();
|
120
118
|
}
|
data/ext/vdefs.h
CHANGED
@@ -64,7 +64,7 @@ typedef struct tagVoronoiState
|
|
64
64
|
int sorted, plot, debug, siteidx;
|
65
65
|
float xmin, xmax, ymin, ymax;
|
66
66
|
Site * sites;
|
67
|
-
void *
|
67
|
+
void * comp;
|
68
68
|
void (* storeT)(int, int, int);
|
69
69
|
void (* storeL)(float, float, float);
|
70
70
|
void (* storeE)(int, int, int);
|
data/ext/voronoi.c
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
#include <ruby.h>
|
5
5
|
#include <vdefs.h>
|
6
|
-
|
6
|
+
#include <stdio.h>
|
7
7
|
|
8
8
|
// Static method definitions: C -> Ruby storage methods.
|
9
9
|
static void storeTriangulationTriplet(const int, const int, const int);
|
@@ -41,8 +41,6 @@ void initialize_state(int debug)
|
|
41
41
|
// TODO: remove C plot references
|
42
42
|
if (rubyvorState.plot)
|
43
43
|
plotinit();
|
44
|
-
|
45
|
-
debug_memory();
|
46
44
|
}
|
47
45
|
|
48
46
|
void
|
@@ -50,28 +48,36 @@ voronoi(Site *(*nextsite)(void))
|
|
50
48
|
{
|
51
49
|
Site * newsite, * bot, * top, * temp, * p, * v ;
|
52
50
|
Point newintstar ;
|
53
|
-
int pm ;
|
51
|
+
int pm , c;
|
54
52
|
Halfedge * lbnd, * rbnd, * llbnd, * rrbnd, * bisector ;
|
55
53
|
Edge * e ;
|
56
54
|
|
55
|
+
c = 0;
|
56
|
+
|
57
57
|
PQinitialize() ;
|
58
58
|
rubyvorState.bottomsite = (*nextsite)() ;
|
59
|
+
if (rubyvorState.debug) fprintf(stderr, "bnys ");
|
59
60
|
out_site(rubyvorState.bottomsite) ;
|
60
61
|
ELinitialize() ;
|
61
62
|
newsite = (*nextsite)() ;
|
63
|
+
|
62
64
|
while (1)
|
63
65
|
{
|
66
|
+
|
67
|
+
if (rubyvorState.debug) fprintf(stderr, "%d ", c++);
|
68
|
+
|
64
69
|
if(!PQempty())
|
65
|
-
{
|
66
70
|
newintstar = PQ_min() ;
|
67
|
-
|
71
|
+
|
68
72
|
if (newsite != (Site *)NULL && (PQempty()
|
69
73
|
|| newsite -> coord.y < newintstar.y
|
70
74
|
|| (newsite->coord.y == newintstar.y
|
71
75
|
&& newsite->coord.x < newintstar.x)))
|
72
76
|
{
|
77
|
+
if (rubyvorState.debug) fprintf(stderr, "nss ");
|
73
78
|
/* new site is smallest */
|
74
79
|
{
|
80
|
+
if (rubyvorState.debug) fprintf(stderr, "bnys ");
|
75
81
|
out_site(newsite) ;
|
76
82
|
}
|
77
83
|
lbnd = ELleftbnd(&(newsite->coord)) ;
|
@@ -98,12 +104,14 @@ voronoi(Site *(*nextsite)(void))
|
|
98
104
|
}
|
99
105
|
else if (!PQempty()) /* intersection is smallest */
|
100
106
|
{
|
107
|
+
if (rubyvorState.debug) fprintf(stderr, "!pqe ");
|
101
108
|
lbnd = PQextractmin() ;
|
102
109
|
llbnd = ELleft(lbnd) ;
|
103
110
|
rbnd = ELright(lbnd) ;
|
104
111
|
rrbnd = ELright(rbnd) ;
|
105
112
|
bot = leftreg(lbnd) ;
|
106
113
|
top = rightreg(rbnd) ;
|
114
|
+
if (rubyvorState.debug) fprintf(stderr, "bnyt ");
|
107
115
|
out_triple(bot, top, rightreg(lbnd)) ;
|
108
116
|
v = lbnd->vertex ;
|
109
117
|
makevertex(v) ;
|
@@ -148,11 +156,9 @@ voronoi(Site *(*nextsite)(void))
|
|
148
156
|
lbnd = ELright(lbnd))
|
149
157
|
{
|
150
158
|
e = lbnd->ELedge ;
|
159
|
+
if (rubyvorState.debug) fprintf(stderr, "bnye ");
|
151
160
|
out_ep(e) ;
|
152
161
|
}
|
153
|
-
|
154
|
-
// After completing calculations
|
155
|
-
debug_memory();
|
156
162
|
}
|
157
163
|
|
158
164
|
|
@@ -171,13 +177,12 @@ storeTriangulationTriplet(const int a, const int b, const int c)
|
|
171
177
|
|
172
178
|
// Create a new triplet from the three incoming points
|
173
179
|
triplet = rb_ary_new2(3);
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
RARRAY(triplet)->ptr[2] = INT2FIX(c);
|
180
|
+
rb_ary_push(triplet, INT2FIX(a));
|
181
|
+
rb_ary_push(triplet, INT2FIX(b));
|
182
|
+
rb_ary_push(triplet, INT2FIX(c));
|
178
183
|
|
179
184
|
// Get the existing raw triangulation
|
180
|
-
trArray = rb_funcall(*(VALUE *)rubyvorState.
|
185
|
+
trArray = rb_funcall(*(VALUE *)rubyvorState.comp, rb_intern("delaunay_triangulation_raw"), 0);
|
181
186
|
|
182
187
|
// Add the new triplet to it
|
183
188
|
rb_ary_push(trArray, triplet);
|
@@ -192,17 +197,16 @@ storeLine(const float a, const float b, const float c)
|
|
192
197
|
|
193
198
|
// Create a new line from the three values
|
194
199
|
line = rb_ary_new2(4);
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
RARRAY(line)->ptr[3] = rb_float_new(c);
|
200
|
+
rb_ary_push(line, ID2SYM(rb_intern("l")));
|
201
|
+
rb_ary_push(line, rb_float_new(a));
|
202
|
+
rb_ary_push(line, rb_float_new(b));
|
203
|
+
rb_ary_push(line, rb_float_new(c));
|
200
204
|
|
201
205
|
// Get the existing raw voronoi diagram
|
202
|
-
lArray = rb_funcall(*(VALUE *)rubyvorState.
|
206
|
+
lArray = rb_funcall(*(VALUE *)rubyvorState.comp, rb_intern("voronoi_diagram_raw"), 0);
|
203
207
|
|
204
208
|
// Add the new line to it
|
205
|
-
rb_ary_push(lArray, line);
|
209
|
+
rb_ary_push(lArray, line);
|
206
210
|
}
|
207
211
|
|
208
212
|
|
@@ -218,17 +222,16 @@ storeEndpoint(const int l, const int v1, const int v2)
|
|
218
222
|
|
219
223
|
// Create a new endpoint from the three values
|
220
224
|
endpoint = rb_ary_new2(4);
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
RARRAY(endpoint)->ptr[3] = INT2FIX(v2);
|
225
|
+
rb_ary_push(endpoint, ID2SYM(rb_intern("e")));
|
226
|
+
rb_ary_push(endpoint, INT2FIX(l));
|
227
|
+
rb_ary_push(endpoint, INT2FIX(v1));
|
228
|
+
rb_ary_push(endpoint, INT2FIX(v2));
|
226
229
|
|
227
230
|
// Get the existing raw voronoi diagram
|
228
|
-
eArray = rb_funcall(*(VALUE *)rubyvorState.
|
231
|
+
eArray = rb_funcall(*(VALUE *)rubyvorState.comp, rb_intern("voronoi_diagram_raw"), 0);
|
229
232
|
|
230
233
|
// Add the new endpoint to it
|
231
|
-
rb_ary_push(eArray, endpoint);
|
234
|
+
rb_ary_push(eArray, endpoint);
|
232
235
|
}
|
233
236
|
|
234
237
|
|
@@ -240,16 +243,15 @@ storeVertex(const float a, const float b)
|
|
240
243
|
|
241
244
|
// Create a new vertex from the coordinates
|
242
245
|
vertex = rb_ary_new2(3);
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
RARRAY(vertex)->ptr[2] = rb_float_new(b);
|
246
|
+
rb_ary_push(vertex, ID2SYM(rb_intern("v")));
|
247
|
+
rb_ary_push(vertex, rb_float_new(a));
|
248
|
+
rb_ary_push(vertex, rb_float_new(b));
|
247
249
|
|
248
250
|
// Get the existing raw voronoi diagram
|
249
|
-
vArray = rb_funcall(*(VALUE *)rubyvorState.
|
251
|
+
vArray = rb_funcall(*(VALUE *)rubyvorState.comp, rb_intern("voronoi_diagram_raw"), 0);
|
250
252
|
|
251
253
|
// Add the new vertex to it
|
252
|
-
rb_ary_push(vArray, vertex);
|
254
|
+
rb_ary_push(vArray, vertex);
|
253
255
|
}
|
254
256
|
|
255
257
|
|
@@ -264,14 +266,13 @@ storeSite(const float x, const float y)
|
|
264
266
|
|
265
267
|
// Create a new site from the coordinates
|
266
268
|
site = rb_ary_new2(3);
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
RARRAY(site)->ptr[2] = rb_float_new(y);
|
269
|
+
rb_ary_push(site, ID2SYM(rb_intern("s")));
|
270
|
+
rb_ary_push(site, rb_float_new(x));
|
271
|
+
rb_ary_push(site, rb_float_new(y));
|
271
272
|
|
272
273
|
// Get the existing raw voronoi diagram
|
273
|
-
sArray = rb_funcall(*(VALUE *)rubyvorState.
|
274
|
+
sArray = rb_funcall(*(VALUE *)rubyvorState.comp, rb_intern("voronoi_diagram_raw"), 0);
|
274
275
|
|
275
276
|
// Add the new site to it
|
276
|
-
rb_ary_push(sArray, site);
|
277
|
+
rb_ary_push(sArray, site);
|
277
278
|
}
|
data/ext/voronoi_interface.c
CHANGED
@@ -10,7 +10,7 @@ VoronoiState rubyvorState;
|
|
10
10
|
|
11
11
|
static VALUE rb_mRubyVor;
|
12
12
|
static VALUE rb_mVDDT;
|
13
|
-
static VALUE
|
13
|
+
static VALUE rb_cComputation;
|
14
14
|
static int repeat, rit;
|
15
15
|
|
16
16
|
// Static method definitions
|
@@ -27,10 +27,10 @@ Init_voronoi_interface(void)
|
|
27
27
|
// Set up our Modules and Class.
|
28
28
|
rb_mRubyVor = rb_define_module("RubyVor");
|
29
29
|
rb_mVDDT = rb_define_module_under(rb_mRubyVor, "VDDT");
|
30
|
-
|
30
|
+
rb_cComputation = rb_define_class_under(rb_mVDDT, "Computation", rb_cObject);
|
31
31
|
|
32
32
|
// Add methods.
|
33
|
-
rb_define_singleton_method(
|
33
|
+
rb_define_singleton_method(rb_cComputation, "from_points", from_points, 1);
|
34
34
|
}
|
35
35
|
|
36
36
|
|
@@ -41,7 +41,7 @@ static VALUE
|
|
41
41
|
from_points(VALUE self, VALUE pointsArray)
|
42
42
|
{
|
43
43
|
//VALUE returnValue;
|
44
|
-
VALUE * inPtr,
|
44
|
+
VALUE * inPtr, newComp;
|
45
45
|
ID x, y;
|
46
46
|
|
47
47
|
long i, inSize;
|
@@ -52,7 +52,7 @@ from_points(VALUE self, VALUE pointsArray)
|
|
52
52
|
for (rit = 0; rit < repeat; rit++) {
|
53
53
|
|
54
54
|
// Require T_ARRAY
|
55
|
-
Check_Type(pointsArray, T_ARRAY);
|
55
|
+
//Check_Type(pointsArray, T_ARRAY);
|
56
56
|
|
57
57
|
// Intern our point access methods
|
58
58
|
x = rb_intern("x");
|
@@ -72,14 +72,13 @@ from_points(VALUE self, VALUE pointsArray)
|
|
72
72
|
|
73
73
|
|
74
74
|
// Initialize rubyvorState
|
75
|
-
initialize_state(
|
75
|
+
initialize_state(/* debug? */ 0);
|
76
|
+
debug_memory();
|
76
77
|
|
77
78
|
// Create our return object.
|
78
|
-
|
79
|
+
newComp = rb_funcall(self, rb_intern("new"), 1, pointsArray);
|
79
80
|
// Store it in rubyvorState so we can populate its values.
|
80
|
-
rubyvorState.
|
81
|
-
|
82
|
-
|
81
|
+
rubyvorState.comp = (void *) &newComp;
|
83
82
|
//
|
84
83
|
// Read in the sites, sort, and compute xmin, xmax, ymin, ymax
|
85
84
|
//
|
@@ -127,22 +126,27 @@ from_points(VALUE self, VALUE pointsArray)
|
|
127
126
|
rubyvorState.ymin = rubyvorState.sites[0].coord.y;
|
128
127
|
rubyvorState.ymax = rubyvorState.sites[rubyvorState.nsites-1].coord.y;
|
129
128
|
|
130
|
-
}
|
129
|
+
}
|
131
130
|
|
132
131
|
|
133
132
|
// Perform the computation
|
134
133
|
voronoi(nextone);
|
134
|
+
debug_memory();
|
135
|
+
|
136
|
+
// Get rid of our comp reference
|
137
|
+
rubyvorState.comp = (void *)NULL;
|
135
138
|
|
136
139
|
// Free our allocated objects
|
137
|
-
free_all();
|
140
|
+
free_all();
|
141
|
+
debug_memory();
|
138
142
|
|
139
143
|
if (rubyvorState.debug)
|
140
|
-
fprintf(stderr,"FINISHED ITERATION %i\n",
|
144
|
+
fprintf(stderr,"FINISHED ITERATION %i\n", rit + 1);
|
141
145
|
|
142
146
|
|
143
|
-
}
|
147
|
+
} // end repeat...
|
144
148
|
|
145
|
-
return
|
149
|
+
return newComp;
|
146
150
|
}
|
147
151
|
|
148
152
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RubyVor
|
2
|
+
|
3
|
+
# Voronoi Digram and Delaunay Triangulation namespace.
|
4
|
+
module VDDT
|
5
|
+
|
6
|
+
# Represents a computation from a set of 2-dimensional points
|
7
|
+
class Computation
|
8
|
+
attr_reader :points, :voronoi_diagram_raw, :delaunay_triangulation_raw
|
9
|
+
|
10
|
+
def initialize(points=[], vd_raw=[], dt_raw=[])
|
11
|
+
@voronoi_diagram_raw = vd_raw
|
12
|
+
@delaunay_triangulation_raw = dt_raw
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
|
17
|
+
# Compute the voronoi diagram and delaunay triangulation from a set of points.
|
18
|
+
#
|
19
|
+
# This implementation uses Steven Fortune's sweepline algorithm, which runs in O(n log n) time and O(n) space.
|
20
|
+
# It is limited to 2-dimensional space, therefore it expects to receive an array of objects that respond to 'x' and 'y' methods.
|
21
|
+
def from_points(p)
|
22
|
+
# Stub; implemented as C function in voronoi_interface.so
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/ruby_vor/point.rb
CHANGED
@@ -1,19 +1,9 @@
|
|
1
1
|
module RubyVor
|
2
|
+
# Basic 2-d point
|
2
3
|
class Point
|
3
4
|
attr_accessor :x, :y
|
4
5
|
def initialize(x=0.0,y=0.0)
|
5
|
-
@x = x
|
6
|
-
@y = y
|
7
|
-
end
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def test_large
|
11
|
-
a = []
|
12
|
-
1000000.times {
|
13
|
-
a << new(100000.0 * rand, 100000.0 * rand)
|
14
|
-
}
|
15
|
-
a
|
16
|
-
end
|
6
|
+
@x = x; @y = y
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
data/lib/ruby_vor/version.rb
CHANGED
data/lib/ruby_vor.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
$:.unshift File.join(File.dirname(__FILE__), '..', 'ext')
|
3
|
-
|
3
|
+
|
4
4
|
require 'ruby_vor/version'
|
5
5
|
require 'ruby_vor/point'
|
6
|
-
require 'ruby_vor/
|
6
|
+
require 'ruby_vor/computation'
|
7
|
+
|
8
|
+
# Require voronoi_interface.so last to clobber old from_points
|
9
|
+
require 'voronoi_interface.so'
|
7
10
|
|
11
|
+
# DOC HERE
|
8
12
|
module RubyVor
|
9
|
-
def self.test_l
|
10
|
-
VDDT::Decomposition.from_points(Point.test_large)
|
11
|
-
end
|
12
|
-
|
13
13
|
end
|
data/rubyvor.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{rubyvor}
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.3"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Brendan Ribera"]
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["brendan.ribera+rubyvor@gmail.com"]
|
10
10
|
s.extensions = ["ext/extconf.rb"]
|
11
11
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
12
|
-
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/vdefs.h", "ext/voronoi.c", "ext/voronoi_interface.c", "lib/ruby_vor.rb", "lib/ruby_vor/
|
12
|
+
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/vdefs.h", "ext/voronoi.c", "ext/voronoi_interface.c", "lib/ruby_vor.rb", "lib/ruby_vor/computation.rb", "lib/ruby_vor/point.rb", "lib/ruby_vor/version.rb", "rubyvor.gemspec", "test/test_voronoi_interface.rb"]
|
13
13
|
s.has_rdoc = true
|
14
14
|
s.homepage = %q{http://github.com/bribera/rubyvor}
|
15
15
|
s.rdoc_options = ["--main", "README.txt"]
|
@@ -12,14 +12,14 @@ class TestVoronoiInterface < MiniTest::Unit::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_diagram_correct
|
15
|
-
# Perform the
|
16
|
-
|
15
|
+
# Perform the computation.
|
16
|
+
comp = RubyVor::VDDT::Computation.from_points(sample_points)
|
17
17
|
|
18
18
|
# Test each raw entry against three basic assertions:
|
19
19
|
# * entry lengths must match
|
20
20
|
# * entry types must match
|
21
21
|
# * entry values must match, with allowance for rounding errors (i.e. within a very small delta)
|
22
|
-
|
22
|
+
comp.voronoi_diagram_raw.each_with_index do |computed_entry, i|
|
23
23
|
sample_entry = example_diagram_raw[i]
|
24
24
|
|
25
25
|
|
@@ -36,13 +36,13 @@ class TestVoronoiInterface < MiniTest::Unit::TestCase
|
|
36
36
|
|
37
37
|
|
38
38
|
def test_triangulation_correct
|
39
|
-
# Perform the
|
40
|
-
|
39
|
+
# Perform the computation.
|
40
|
+
comp = RubyVor::VDDT::Computation.from_points(sample_points)
|
41
41
|
|
42
42
|
# One assertion:
|
43
43
|
# * raw triangulation must match exactly.
|
44
44
|
|
45
|
-
assert_equal example_triangulation_raw,
|
45
|
+
assert_equal example_triangulation_raw, comp.delaunay_triangulation_raw
|
46
46
|
end
|
47
47
|
|
48
48
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendan Ribera
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- ext/voronoi.c
|
49
49
|
- ext/voronoi_interface.c
|
50
50
|
- lib/ruby_vor.rb
|
51
|
-
- lib/ruby_vor/
|
51
|
+
- lib/ruby_vor/computation.rb
|
52
52
|
- lib/ruby_vor/point.rb
|
53
53
|
- lib/ruby_vor/version.rb
|
54
54
|
- rubyvor.gemspec
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module RubyVor
|
2
|
-
module VDDT
|
3
|
-
class Decomposition
|
4
|
-
attr_reader :voronoi_diagram_raw, :delaunay_triangulation_raw
|
5
|
-
def initialize(vd_raw=[], dt_raw=[])
|
6
|
-
@voronoi_diagram_raw = vd_raw
|
7
|
-
@delaunay_triangulation_raw = dt_raw
|
8
|
-
end
|
9
|
-
|
10
|
-
private
|
11
|
-
|
12
|
-
def voronoi_diagram_raw=(v)
|
13
|
-
@voronoi_diagram_raw = v
|
14
|
-
end
|
15
|
-
|
16
|
-
def delaunay_triangulation_raw=(v)
|
17
|
-
@delaunay_triangulation_raw = v
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|