Skip to content

Commit 4068732

Browse files
committed
calculate bbox only for outer ring
1 parent 7cd2af0 commit 4068732

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/feature.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// [ringLen, ringSize, x,y,z, ..., ringLen, ringSize, x,y,z, ..., ...]
1717
// where `ringLen` is the coord-triple count and `ringSize` is the ring's length
1818
// (LINE, unsigned) or signed area (POLYGON). The whole feature lives in a
19-
// single Array — no per-ring sub-arrays.
19+
// single Float64Array — no per-ring sub-arrays.
2020
//
2121
// When lineMetrics is on, LINE features always have a single ring, and
2222
// `feature.start` / `feature.end` carry the clip metrics (in source-length
@@ -53,11 +53,15 @@ export function createFeature(id, type, geom, tags) {
5353
if (type === POINT) {
5454
calcBBox(feature, geom, 0, geom.length);
5555
} else {
56+
// polygon holes lie inside their outer ring, so they can't extend the
57+
// bbox — skip them (ringSize < 0 after canonical winding)
58+
const outerOnly = type === POLYGON;
5659
for (let i = 0; i < geom.length;) {
5760
const ringLen = geom[i];
61+
const ringSize = geom[i + 1];
5862
const coords0 = i + 2;
5963
const coordsEnd = coords0 + ringLen * 3;
60-
calcBBox(feature, geom, coords0, coordsEnd);
64+
if (!outerOnly || ringSize > 0) calcBBox(feature, geom, coords0, coordsEnd);
6165
i = coordsEnd;
6266
}
6367
}

0 commit comments

Comments
 (0)