This commit is contained in:
Mike Bostock 2013-04-30 15:30:56 -07:00
Родитель 8b29fd10d0
Коммит f76f564451
2 изменённых файлов: 11 добавлений и 7 удалений

Просмотреть файл

@ -95,7 +95,7 @@ d3.geom.hull = function(vertices) {
// construct the hull
var poly = [];
for (i = 0; i < sp; ++i) poly.push(data[stack[i]]);
for (i = sp - 1; i >= 0; --i) poly.push(data[stack[i]]);
return poly;
}

Просмотреть файл

@ -1,4 +1,5 @@
var vows = require("vows"),
_ = require("../../"),
load = require("../load"),
assert = require("../assert");
@ -26,11 +27,14 @@ suite.addBatch({
"of two points is empty": function(h) {
assert.deepEqual(h([[200, 200], [760, 300]]), []);
},
"for three points is empty": function(h) {
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[200, 200], [760, 300], [500, 500]]);
"for three points": function(h) {
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[500, 500], [760, 300], [200, 200]]);
},
"for four points": function(h) {
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[200, 200], [760, 300], [500, 500]]);
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[500, 500], [760, 300], [200, 200]]);
},
"returns a counter-clockwise polygon": function(h) {
assert.greater(_.geom.polygon(h([[200, 200], [760, 300], [500, 500], [400, 400]])).area(), 0);
}
},
"the hull layout with custom accessors": {
@ -38,7 +42,7 @@ suite.addBatch({
return hull().x(function(d) { return d.x; }).y(function(d) { return d.y; });
},
"of four points": function(h) {
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}]);
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}]);
}
},
"the default hull layout applied directly": {
@ -52,10 +56,10 @@ suite.addBatch({
return h([[200, 200], [760, 300]]);
},
"for three points": function(h) {
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[200, 200], [760, 300], [500, 500]]);
assert.deepEqual(h([[200, 200], [760, 300], [500, 500]]), [[500, 500], [760, 300], [200, 200]]);
},
"for four points": function(h) {
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[200, 200], [760, 300], [500, 500]]);
assert.deepEqual(h([[200, 200], [760, 300], [500, 500], [400, 400]]), [[500, 500], [760, 300], [200, 200]]);
}
}
}