Skip to content

Commit

Permalink
Don’t repeat corners. Related #42.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed May 23, 2018
1 parent ed04e98 commit 063adee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/voronoi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/voronoi-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
});

Expand Down

0 comments on commit 063adee

Please sign in to comment.