Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/earcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,26 +336,35 @@ function findHoleBridge(hole, outerNode) {
tanMin = Infinity,
tan;

p = m.next;
p = m;

while (p !== stop) {
do {
if (hx >= p.x && p.x >= mx && hx !== p.x &&
pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {

tan = Math.abs(hy - p.y) / (hx - p.x); // tangential

if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
if (locallyInside(p, hole) &&
(tan < tanMin || (tan === tanMin && (p.x > m.x || (p.x === m.x && sectorContainsSector(m, p)))))) {
m = p;
tanMin = tan;
}
}

p = p.next;
}
} while (p !== stop);

return m;
}

// whether sector in vertex m contains sector in vertex p in the same coordinates
function sectorContainsSector(m, p) {
return (
(area(m.prev, m, p.prev) < 0 || area(p.prev, m, m.next) < 0) &&
(area(m.prev, m, p.next) < 0 || area(p.next, m, m.next) < 0)
);
}

// interlink polygon nodes in z-order
function indexCurve(start, minX, minY, invSize) {
var p = start;
Expand Down
3 changes: 2 additions & 1 deletion test/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"issue107": 0,
"issue111": 19,
"boxy": 57,
"collinear-diagonal": 14
"collinear-diagonal": 14,
"issue119": 18
},
"errors": {
"dude": 2e-15,
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/issue119.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
[[2,12],[2,20],[25,20],[25,12]],
[[7,18],[7,15],[5,15]],
[[19,18],[19,17],[17,17]],
[[19,17],[21,17],[19,16]],
[[7,15],[9,15],[7,13]]
]