Skip to content

Commit 54cbb0d

Browse files
committed
fix hashed earcut not taking the first point into account, close #186
1 parent cad85d2 commit 54cbb0d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/earcut.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export default function earcut(data, holeIndices, dim = 2) {
1414

1515
// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
1616
if (data.length > 80 * dim) {
17-
minX = Infinity;
18-
minY = Infinity;
19-
let maxX = -Infinity;
20-
let maxY = -Infinity;
17+
minX = data[0];
18+
minY = data[1];
19+
let maxX = minX;
20+
let maxY = minY;
2121

2222
for (let i = dim; i < outerLen; i += dim) {
2323
const x = data[i];

test/expected.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"infinite-loop-jhl": 0,
5151
"filtered-bridge-jhl": 25,
5252
"issue149": 2,
53-
"issue142": 4
53+
"issue142": 4,
54+
"issue186": 41
5455
},
5556
"errors": {
5657
"dude": 2e-15,
@@ -71,4 +72,4 @@
7172
"bad-hole": 0.04,
7273
"issue16": 8e-16
7374
}
74-
}
75+
}

test/fixtures/issue186.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[[[0,200],[5,200],[10,200],[15,200],[20,200],[25,200],[30,200],[35,200],[40,200],[45,200],[50,200],[55,200],[60,200],[65,200],[70,200],[75,200],[80,200],[85,200],[90,200],[95,200],[100,200],[105,200],[110,200],[115,200],[120,200],[125,200],[130,200],[135,200],[140,200],[145,200],[150,200],[155,200],[160,200],[165,200],[170,200],[175,200],[180,200],[185,200],[190,200],[195,200],[200,200],[200,100],[205,100],[210,100],[215,100],[220,100],[225,100],[230,100],[235,100],[240,100],[245,100],[250,100],[255,100],[260,100],[265,100],[270,100],[275,100],[280,100],[285,100],[290,100],[295,100],[300,100],[305,100],[310,100],[315,100],[320,100],[325,100],[330,100],[335,100],[340,100],[345,100],[350,100],[355,100],[360,100],[365,100],[370,100],[375,100],[380,100],[385,100],[390,100],[395,100],[400,100],[400,200]]]

0 commit comments

Comments
 (0)