Skip to content

Commit 934e54d

Browse files
committed
fix another hole bridging edge case, close #221
1 parent 77019d3 commit 934e54d

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎src/earcut.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ function eliminateHole(hole, outerNode) {
354354
// heal collinear/coincident points around the two new slit edges, but leave bridge2 alone: dropping it as collinear
355355
// would leave bridge lying on the healed edge, where a later hole could bridge into it from outside its sector
356356
filterPoints(bridgeReverse.prev, bridgeReverse);
357+
358+
// likewise, if bridge lies strictly between its prev and hole, healing would drop it and leave bridge2 on the healed
359+
// edge; skip the heal then (a spike at bridge, e.g. a hole touching an outer edge, still needs it)
360+
const a = bridge.prev;
361+
if (area(a, bridge, hole) === 0 && (a.x - bridge.x) * (hole.x - bridge.x) + (a.y - bridge.y) * (hole.y - bridge.y) < 0) return bridge;
362+
357363
return filterPoints(bridge, bridge.next);
358364
}
359365

‎test/expected.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"issue142": 4,
6060
"issue186": 41,
6161
"issue219": 11,
62+
"issue221": 12,
6263
"issue147": 30
6364
},
6465
"errors": {

‎test/fixtures/issue221.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[[2,7],[0,9],[6,6],[5,0]],[[3,6],[5,1],[4,3]],[[3,7],[4,4],[5,2]]]

0 commit comments

Comments
 (0)