Skip to content

Commit

Permalink
fix race condition with collinear split diagonal (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner authored Sep 17, 2019
1 parent 005252c commit 2de038e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/earcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,11 @@ function equals(p1, p2) {
function intersects(p1, q1, p2, q2) {
if ((equals(p1, p2) && equals(q1, q2)) ||
(equals(p1, q2) && equals(p2, q1))) return true;
return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&
area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
var a0 = area(p1, q1, p2);
var a1 = area(p1, q1, q2);
var a2 = area(p2, q2, p1);
var a3 = area(p2, q2, q1);
return (a0 === 0 && a1 === 0) || (a0 > 0 !== a1 > 0 && a2 > 0 !== a3 > 0);
}

// check if a polygon diagonal intersects any polygon segments
Expand Down
3 changes: 2 additions & 1 deletion test/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"issue83": 0,
"issue107": 0,
"issue111": 19,
"boxy": 56
"boxy": 57,
"collinear-diagonal": 14
},
"errors": {
"dude": 2e-15,
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/collinear-diagonal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[[3468,1913],[3486,1884],[3413,1869],[3322,1869],[3413,1854],[3413,1869],[3486,1869],[3486,1884],[3504,1884],[3504,1869],[3432,1869],[3432,1854],[3395,1854],[3432,1839],[3432,1854],[3450,1839],[3341,1839],[3341,1825],[3195,1825],[3341,1810],[3341,1825],[3450,1825],[3523,1854],[3523,1913]]]

0 comments on commit 2de038e

Please sign in to comment.