Skip to content

Commit

Permalink
remove zero-length edges from clipped voronoi cells
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Jul 23, 2019
1 parent b0a0bb4 commit 6cde401
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/voronoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export default class Voronoi {
if (points === null) return;
context.moveTo(points[0], points[1]);
for (let i = 2, n = points.length; i < n; i += 2) {
context.lineTo(points[i], points[i + 1]);
if (points[i] !== points[i-2] || points[i+1] !== points[i-1])
context.lineTo(points[i], points[i + 1]);
}
context.closePath();
return buffer && buffer.value();
Expand Down
5 changes: 5 additions & 0 deletions test/voronoi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ tape("voronoi.update() updates a degenerate voronoi", test => {
const p = voronoi.update().cellPolygon(1);
test.deepEqual(p, [[-500, 500], [-500, -140], [-240, -140], [-140, 60], [-140, 500], [-500, 500]]);
});

tape("zero-length edges are removed", test => {
const voronoi = Delaunay.from([[50, 10], [10, 50], [10, 10], [200, 100]]).voronoi([40, 40, 440, 180]);
test.equal(voronoi.cellPolygon(0).length, 4);
})

0 comments on commit 6cde401

Please sign in to comment.