Fix #993; d3.geom.hull is now ccw.
This commit is contained in:
Родитель
8b29fd10d0
Коммит
f76f564451
|
@ -95,7 +95,7 @@ d3.geom.hull = function(vertices) {
|
||||||
|
|
||||||
// construct the hull
|
// construct the hull
|
||||||
var poly = [];
|
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;
|
return poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
var vows = require("vows"),
|
var vows = require("vows"),
|
||||||
|
_ = require("../../"),
|
||||||
load = require("../load"),
|
load = require("../load"),
|
||||||
assert = require("../assert");
|
assert = require("../assert");
|
||||||
|
|
||||||
|
@ -26,11 +27,14 @@ suite.addBatch({
|
||||||
"of two points is empty": function(h) {
|
"of two points is empty": function(h) {
|
||||||
assert.deepEqual(h([[200, 200], [760, 300]]), []);
|
assert.deepEqual(h([[200, 200], [760, 300]]), []);
|
||||||
},
|
},
|
||||||
"for three points is empty": function(h) {
|
"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) {
|
"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": {
|
"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; });
|
return hull().x(function(d) { return d.x; }).y(function(d) { return d.y; });
|
||||||
},
|
},
|
||||||
"of four points": function(h) {
|
"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": {
|
"the default hull layout applied directly": {
|
||||||
|
@ -52,10 +56,10 @@ suite.addBatch({
|
||||||
return h([[200, 200], [760, 300]]);
|
return h([[200, 200], [760, 300]]);
|
||||||
},
|
},
|
||||||
"for three points": function(h) {
|
"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) {
|
"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]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче