Skip to content

Commit

Permalink
fix a race condition with coincident chain of holes
Browse files Browse the repository at this point in the history
Closes #111.
  • Loading branch information
mourner committed Feb 5, 2019
1 parent ad016a4 commit 7564bd1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/earcut.js
Expand Up @@ -449,7 +449,7 @@ function getLeftmost(start) {
var p = start,
leftmost = start;
do {
if (p.x < leftmost.x) leftmost = p;
if (p.x < leftmost.x || (p.x === leftmost.x && p.y < leftmost.y)) leftmost = p;
p = p.next;
} while (p !== start);

Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/issue111.json
@@ -0,0 +1,6 @@
[
[[800,4520],[800,4700],[796,4702],[800,4692],[734,4644],[734,4628],[730,4632],[726,4630],[718,4640],[690,4623],[722,4598],[690,4608],[690,4520],[800,4520]],
[[718,4640],[716,4630],[710,4628],[718,4640]],
[[734,4610],[734,4628],[740,4622],[734,4610]],
[[734,4610],[745,4600],[734,4602],[734,4610]]
]
5 changes: 3 additions & 2 deletions test/test.js
Expand Up @@ -12,8 +12,8 @@ areaTest('water2', 1212);
areaTest('water3', 197);
areaTest('water3b', 25);
areaTest('water4', 705);
areaTest('water-huge', 5174, 0.0011);
areaTest('water-huge2', 4461, 0.0028);
areaTest('water-huge', 5175, 0.0011);
areaTest('water-huge2', 4462, 0.0028);
areaTest('degenerate', 0);
areaTest('bad-hole', 42, 0.019);
areaTest('empty-square', 0);
Expand All @@ -37,6 +37,7 @@ areaTest('shared-points', 4);
areaTest('bad-diagonals', 7);
areaTest('issue83', 0);
areaTest('issue107', 0);
areaTest('issue111', 0);

test('indices-2d', function (t) {
var indices = earcut([10, 0, 0, 50, 60, 60, 70, 10]);
Expand Down

0 comments on commit 7564bd1

Please sign in to comment.