From b68d6350bb41a2b255ba2890d4895b3825afe0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 9 Jul 2019 17:55:23 +0200 Subject: [PATCH] A test highlighting that the number of triangles can change between updates ref: https://github.com/d3/d3-delaunay/issues/74#issuecomment-508819437 --- test/voronoi-test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/voronoi-test.js b/test/voronoi-test.js index d0e8719..9ed09ec 100644 --- a/test/voronoi-test.js +++ b/test/voronoi-test.js @@ -30,3 +30,16 @@ tape("voronoi.update() updates the voronoi", test => { const p = voronoi.update().cellPolygon(1); // correct after voronoi.update test.deepEqual(p, [[-500, 500], [-500, -140], [-240, -140], [-140, 60], [-140, 500], [-500, 500]]); }); + +tape("voronoi.update() updates a degenerate voronoi", test => { + const pts = [10, 10, -290, 10, 10, -290, -290, -290, -90, -90]; + let delaunay = new Delaunay(Array.from({length: pts.length}).fill(0)); + let voronoi = delaunay.voronoi([-500, -500, 500, 500]); + test.deepEqual(voronoi.cellPolygon(0), [ [ 500, -500 ], [ 500, 500 ], [ -500, 500 ], [ -500, -500 ], [ 500, -500 ] ]); + test.equal(voronoi.cellPolygon(1), null); + for (let i = 0; i < delaunay.points.length; i++) { + delaunay.points[i] = pts[i]; + } + const p = voronoi.update().cellPolygon(1); + test.deepEqual(p, [[-500, 500], [-500, -140], [-240, -140], [-140, 60], [-140, 500], [-500, 500]]); +});