Skip to content

Commit 112ec6f

Browse files
committed
d3.geom.voronoi: always assign input data.
1 parent 2f1c62d commit 112ec6f

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

d3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,8 +4070,8 @@ d3 = function() {
40704070
return triangles;
40714071
};
40724072
d3.geom.voronoi = function(points) {
4073-
var size = null, x = d3_svg_lineX, y = d3_svg_lineY, clip, compat;
4074-
if (compat = arguments.length) return voronoi(points);
4073+
var size = null, x = d3_svg_lineX, y = d3_svg_lineY, clip;
4074+
if (arguments.length) return voronoi(points);
40754075
function voronoi(data) {
40764076
var points = [], polygons = data.map(function() {
40774077
return [];
@@ -4139,7 +4139,7 @@ d3 = function() {
41394139
}
41404140
});
41414141
if (clip) for (i = 0; i < n; ++i) clip(polygons[i]);
4142-
if (!compat) for (i = 0; i < n; ++i) polygons[i].point = data[i];
4142+
for (i = 0; i < n; ++i) polygons[i].point = data[i];
41434143
return polygons;
41444144
}
41454145
voronoi.x = function(_) {

d3.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/geom/voronoi.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ d3.geom.voronoi = function(points) {
3030
var size = null,
3131
x = d3_svg_lineX,
3232
y = d3_svg_lineY,
33-
clip,
34-
compat;
33+
clip;
3534

3635
// For backwards-compatibility.
37-
if (compat = arguments.length) return voronoi(points);
36+
if (arguments.length) return voronoi(points);
3837

3938
function voronoi(data) {
4039
var points = [],
@@ -127,7 +126,7 @@ d3.geom.voronoi = function(points) {
127126
});
128127

129128
if (clip) for (i = 0; i < n; ++i) clip(polygons[i]);
130-
if (!compat) for (i = 0; i < n; ++i) polygons[i].point = data[i];
129+
for (i = 0; i < n; ++i) polygons[i].point = data[i];
131130

132131
return polygons;
133132
}

test/geom/voronoi-test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,42 +144,48 @@ suite.addBatch({
144144
}
145145
},
146146

147-
"the default voronoi layout used directly": {
147+
"the default voronoi layout applied directly": {
148148
"with zero points": {
149149
"returns the empty array": function(voronoi) {
150150
assert.deepEqual(voronoi([]), []);
151151
}
152152
},
153153
"with one point": {
154154
"returns the semi-infinite bounding box": function(voronoi) {
155-
assert.deepEqual(voronoi([[50, 50]], 100, 100), [[[-1000000,-1000000],[-1000000,1000000],[1000000,1000000],[1000000,-1000000]]]);
155+
assert.deepEqual(asArray(voronoi([[50, 50]], 100, 100)), [[[-1000000,-1000000],[-1000000,1000000],[1000000,1000000],[1000000,-1000000]]]);
156156
}
157157
},
158158
"with two points": {
159159
"separated by a line at 90° (vertical)": function(voronoi) {
160-
assert.deepEqual(voronoi([[50, 25], [50, 75]], 100, 100), [[[-1000000,50],[1000000,50],[-1000000,-1000000],[1000000,-1000000]],[[-1000000,50],[1000000,50],[-1000000,1000000],[1000000,1000000]]]);
161-
assert.deepEqual(voronoi([[50, 75], [50, 25]], 100, 100), [[[-1000000,50],[1000000,50],[-1000000,1000000],[1000000,1000000]],[[-1000000,50],[1000000,50],[-1000000,-1000000],[1000000,-1000000]]]);
160+
assert.deepEqual(asArray(voronoi([[50, 25], [50, 75]], 100, 100)), [[[-1000000,50],[1000000,50],[-1000000,-1000000],[1000000,-1000000]],[[-1000000,50],[1000000,50],[-1000000,1000000],[1000000,1000000]]]);
161+
assert.deepEqual(asArray(voronoi([[50, 75], [50, 25]], 100, 100)), [[[-1000000,50],[1000000,50],[-1000000,1000000],[1000000,1000000]],[[-1000000,50],[1000000,50],[-1000000,-1000000],[1000000,-1000000]]]);
162162
},
163163
"separated by a line at 0° (horizontal)": function(voronoi) {
164-
assert.deepEqual(voronoi([[25, 50], [75, 50]], 100, 100), [[[50,1000000],[50,-1000000],[-1000000,-1000000],[-1000000,1000000]],[[50,-1000000],[50,1000000],[1000000,-1000000],[1000000,1000000]]]);
165-
assert.deepEqual(voronoi([[75, 50], [25, 50]], 100, 100), [[[50,-1000000],[50,1000000],[1000000,-1000000],[1000000,1000000]],[[50,1000000],[50,-1000000],[-1000000,-1000000],[-1000000,1000000]]]);
164+
assert.deepEqual(asArray(voronoi([[25, 50], [75, 50]], 100, 100)), [[[50,1000000],[50,-1000000],[-1000000,-1000000],[-1000000,1000000]],[[50,-1000000],[50,1000000],[1000000,-1000000],[1000000,1000000]]]);
165+
assert.deepEqual(asArray(voronoi([[75, 50], [25, 50]], 100, 100)), [[[50,-1000000],[50,1000000],[1000000,-1000000],[1000000,1000000]],[[50,1000000],[50,-1000000],[-1000000,-1000000],[-1000000,1000000]]]);
166166
},
167167
"separated by a line at 45° (diagonal)": function(voronoi) {
168-
assert.deepEqual(voronoi([[25, 25], [75, 75]], 100, 100), [[[-999900,1000000],[1000100,-1000000],[-1000000,-1000000]],[[-999900,1000000],[1000100,-1000000],[1000000,1000000]]]);
169-
assert.deepEqual(voronoi([[75, 25], [25, 75]], 100, 100), [[[-1000000,-1000000],[1000000,1000000],[1000000,-1000000]],[[-1000000,-1000000],[1000000,1000000],[-1000000,1000000]]]);
168+
assert.deepEqual(asArray(voronoi([[25, 25], [75, 75]], 100, 100)), [[[-999900,1000000],[1000100,-1000000],[-1000000,-1000000]],[[-999900,1000000],[1000100,-1000000],[1000000,1000000]]]);
169+
assert.deepEqual(asArray(voronoi([[75, 25], [25, 75]], 100, 100)), [[[-1000000,-1000000],[1000000,1000000],[1000000,-1000000]],[[-1000000,-1000000],[1000000,1000000],[-1000000,1000000]]]);
170170
},
171171
"separated by an arbitrary diagonal": function(voronoi) {
172-
assert.deepEqual(voronoi([[25, 25], [50, 75]], 100, 100), [[[-1000000,500068.75],[1000000,-499931.25],[-1000000,-1000000],[1000000,-1000000]],[[-1000000,500068.75],[1000000,-499931.25],[-1000000,1000000],[1000000,1000000]]]);
173-
assert.deepEqual(voronoi([[25, 25], [75, 50]], 100, 100), [[[-499931.25,1000000],[500068.75,-1000000],[-1000000,1000000],[1000000,1000000]], [[-499931.25,1000000],[500068.75,-1000000],[-1000000,-1000000],[1000000,-1000000]]]);
172+
assert.deepEqual(asArray(voronoi([[25, 25], [50, 75]], 100, 100)), [[[-1000000,500068.75],[1000000,-499931.25],[-1000000,-1000000],[1000000,-1000000]],[[-1000000,500068.75],[1000000,-499931.25],[-1000000,1000000],[1000000,1000000]]]);
173+
assert.deepEqual(asArray(voronoi([[25, 25], [75, 50]], 100, 100)), [[[-499931.25,1000000],[500068.75,-1000000],[-1000000,1000000],[1000000,1000000]], [[-499931.25,1000000],[500068.75,-1000000],[-1000000,-1000000],[1000000,-1000000]]]);
174174
}
175175
},
176176
"with three points": {
177177
"collinear": function(voronoi) {
178-
assert.deepEqual(voronoi([[25, 25], [50, 50], [75, 75]], 100, 100), [[[-999925,1000000],[1000075,-1000000],[-1000000,-1000000]],[[-999925,1000000],[-999875,1000000],[1000125,-1000000],[1000075,-1000000]],[[-999875,1000000],[1000125,-1000000],[1000000,1000000]]]);
178+
assert.deepEqual(asArray(voronoi([[25, 25], [50, 50], [75, 75]], 100, 100)), [[[-999925,1000000],[1000075,-1000000],[-1000000,-1000000]],[[-999925,1000000],[-999875,1000000],[1000125,-1000000],[1000075,-1000000]],[[-999875,1000000],[1000125,-1000000],[1000000,1000000]]]);
179179
}
180180
}
181181
}
182182
}
183183
});
184184

185185
suite.export(module);
186+
187+
function asArray(array) {
188+
return array.map(function(d) {
189+
return Array.prototype.slice.call(d);
190+
});
191+
}

0 commit comments

Comments
 (0)