Skip to content

Commit

Permalink
fix Eberly-3 hole algorithm case, ref #56
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Mar 17, 2016
1 parent ee1adb0 commit cf5f2f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/earcut.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ function findHoleBridge(hole, outerNode) {
var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
if (x <= hx && x > qx) {
qx = x;
if (x === hx) {
if (hy === p.y) return p;
if (hy === p.next.y) return p.next;
}
m = p.x < p.next.x ? p : p.next;
}
}
Expand All @@ -307,7 +311,7 @@ function findHoleBridge(hole, outerNode) {

if (!m) return null;

if (hole.x === m.x) return m.prev; // hole touches outer segment; pick lower endpoint
if (hx === qx) return m.prev; // hole touches outer segment; pick lower endpoint

// look for points inside the triangle of hole point, segment intersection and endpoint;
// if there are no points found, we have a valid connection;
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/eberly-3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[[2328,2408],[2328,2472],[2344,2472],[2344,2432],[2384,2448],[2384,2536],[2408,2552],[2448,2544],[2456,2560],[2496,2544],[2480,2624],[2456,2664],[2424,2680],[2400,2768],[2376,2768],[2368,2704],[2336,2704],[2264,2784],[2216,2784],[2200,2760],[2168,2760],[2152,2744],[2128,2744],[2128,2784],[2072,2768],[2032,2720],[2000,2720],[2000,2688],[1936,2696],[1920,2736],[1888,2728],[1896,2696],[1928,2688],[1928,2664],[1896,2664],[1896,2640],[1912,2632],[1872,2608],[1888,2576],[2056,2576],[2088,2600],[2184,2608],[2216,2632],[2256,2624],[2248,2600],[2216,2592],[2192,2560],[2120,2576],[2072,2544],[2096,2544],[2080,2520],[2080,2488],[2096,2480],[2080,2448],[2096,2432],[2176,2496],[2200,2488],[2224,2528],[2248,2528],[2240,2488],[2256,2472],[2280,2480],[2264,2416],[2272,2392],[2328,2408]],[[2320,2608],[2304,2640],[2312,2664],[2360,2632],[2352,2608],[2320,2608]],[[1912,2632],[1936,2632],[1936,2616],[1912,2608],[1912,2632]]]
1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ areaTest('touching-holes', 57);
areaTest('hole-touching-outer', 77);
areaTest('hilbert', 1024);
areaTest('issue45', 10);
areaTest('eberly-3', 73);
areaTest('eberly-6', 1429);
areaTest('issue52', 109);

Expand Down

0 comments on commit cf5f2f1

Please sign in to comment.