From 063adee9404c7a3643fcf10667c0296429a31373 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 23 May 2018 09:27:24 -0700 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20repeat=20corners.=20Related=20#?= =?UTF-8?q?42.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/voronoi.js | 14 +++++++------- test/voronoi-test.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/voronoi.js b/src/voronoi.js index 76eaadf..1f69e4d 100644 --- a/src/voronoi.js +++ b/src/voronoi.js @@ -264,19 +264,19 @@ export default class Voronoi { } _edge(i, e0, e1, P, j) { while (e0 !== e1) { - let cx, cy; + let x, y; switch (e0) { case 0b0101: e0 = 0b0100; continue; // top-left - case 0b0100: e0 = 0b0110, cx = this.xmax, cy = this.ymin; break; // top + case 0b0100: e0 = 0b0110, x = this.xmax, y = this.ymin; break; // top case 0b0110: e0 = 0b0010; continue; // top-right - case 0b0010: e0 = 0b1010, cx = this.xmax, cy = this.ymax; break; // right + case 0b0010: e0 = 0b1010, x = this.xmax, y = this.ymax; break; // right case 0b1010: e0 = 0b1000; continue; // bottom-right - case 0b1000: e0 = 0b1001, cx = this.xmin, cy = this.ymax; break; // bottom + case 0b1000: e0 = 0b1001, x = this.xmin, y = this.ymax; break; // bottom case 0b1001: e0 = 0b0001; continue; // bottom-left - case 0b0001: e0 = 0b0101, cx = this.xmin, cy = this.ymin; break; // left + case 0b0001: e0 = 0b0101, x = this.xmin, y = this.ymin; break; // left } - if (this.contains(i, cx, cy)) { - P.splice(j, 0, cx, cy), j += 2; + if ((P[j] !== x || P[j + 1] !== y) && this.contains(i, x, y)) { + P.splice(j, 0, x, y), j += 2; } } return j; diff --git a/test/voronoi-test.js b/test/voronoi-test.js index 6239b12..38d42f3 100644 --- a/test/voronoi-test.js +++ b/test/voronoi-test.js @@ -23,7 +23,7 @@ tape("voronoi.renderCell(i, context) handles midpoint coincident with circumcent let voronoi = Delaunay.from([[0, 0], [1, 0], [0, 1]]).voronoi([-1, -1, 2, 2]); let context = new Context; test.equal((voronoi.renderCell(0, context), context.toString()), `M-1,-1L0.5,-1L0.5,0.5L-1,0.5Z`); - test.equal((voronoi.renderCell(1, context), context.toString()), `M2,-1L2,2L2,2L0.5,0.5L0.5,-1Z`); + test.equal((voronoi.renderCell(1, context), context.toString()), `M2,-1L2,2L0.5,0.5L0.5,-1Z`); test.equal((voronoi.renderCell(2, context), context.toString()), `M-1,2L-1,0.5L0.5,0.5L2,2Z`); });