Skip to content

Commit f76f564

Browse files
committed
Fix d3#993; d3.geom.hull is now ccw.
1 parent 8b29fd1 commit f76f564

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/geom/hull.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ d3.geom.hull = function(vertices) {
9595

9696
// construct the hull
9797
var poly = [];
98-
for (i = 0; i < sp; ++i) poly.push(data[stack[i]]);
98+
for (i = sp - 1; i >= 0; --i) poly.push(data[stack[i]]);
9999
return poly;
100100
}
101101

test/geom/hull-test.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var vows = require("vows"),
2+
_ = require("../../"),
23
load = require("../load"),
34
assert = require("../assert");
45

@@ -26,19 +27,22 @@ suite.addBatch({
2627
"of two points is empty": function(h) {
2728
assert.deepEqual(h([[200, 200], [760, 300]]), []);
2829
},
29-
"for three points is empty": function(h) {
30-
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[200, 200], [760, 300], [500, 500]]);
30+
"for three points": function(h) {
31+
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[500, 500], [760, 300], [200, 200]]);
3132
},
3233
"for four points": function(h) {
33-
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[200, 200], [760, 300], [500, 500]]);
34+
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[500, 500], [760, 300], [200, 200]]);
35+
},
36+
"returns a counter-clockwise polygon": function(h) {
37+
assert.greater(_.geom.polygon(h([[200, 200], [760, 300], [500, 500], [400, 400]])).area(), 0);
3438
}
3539
},
3640
"the hull layout with custom accessors": {
3741
topic: function(hull) {
3842
return hull().x(function(d) { return d.x; }).y(function(d) { return d.y; });
3943
},
4044
"of four points": function(h) {
41-
assert.deepEqual(h([{x: 200, y: 200}, {x: 760, y: 300}, {x: 500, y: 500}, {x: 400, y: 400}]), [{x: 200, y: 200}, {x: 760, y: 300}, {x: 500, y: 500}]);
45+
assert.deepEqual(h([{x: 200, y: 200}, {x: 760, y: 300}, {x: 500, y: 500}, {x: 400, y: 400}]), [{x: 500, y: 500}, {x: 760, y: 300}, {x: 200, y: 200}]);
4246
}
4347
},
4448
"the default hull layout applied directly": {
@@ -52,10 +56,10 @@ suite.addBatch({
5256
return h([[200, 200], [760, 300]]);
5357
},
5458
"for three points": function(h) {
55-
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[200, 200], [760, 300], [500, 500]]);
59+
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[500, 500], [760, 300], [200, 200]]);
5660
},
5761
"for four points": function(h) {
58-
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[200, 200], [760, 300], [500, 500]]);
62+
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[500, 500], [760, 300], [200, 200]]);
5963
}
6064
}
6165
}

0 commit comments

Comments
 (0)