Skip to content

Commit 4969da8

Browse files
Olivier Bernardclaude
authored andcommitted
refactor: Replace Clipper2 with Turf bbox-clip for simplified geometry clipping
Replace the Clipper2 polygon clipping library with Turf's bbox-clip, which provides a simpler, more maintainable solution for geometry clipping operations. This reduces dependency complexity while preserving all clipping functionality. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent 8c3b5bc commit 4969da8

10 files changed

Lines changed: 165 additions & 119 deletions

File tree

bun.lock

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@
4646
"@kobalte/core": "^0.13.11",
4747
"@mapbox/vector-tile": "^2.0.4",
4848
"@turf/area": "^7.3.4",
49-
"@turf/bbox-clip": "^7.3.4",
5049
"@turf/bearing": "^7.3.4",
5150
"@turf/boolean-contains": "^7.3.4",
51+
"@turf/boolean-intersects": "^7.3.4",
5252
"@turf/boolean-point-in-polygon": "^7.3.4",
5353
"@turf/centroid": "^7.3.4",
5454
"@turf/distance": "^7.3.4",
5555
"@turf/helpers": "^7.3.4",
56+
"@turf/intersect": "^7.3.4",
5657
"@turf/length": "^7.3.4",
5758
"@turf/line-slice-along": "^7.3.4",
59+
"@turf/line-split": "^7.3.4",
5860
"@turf/point-grid": "^7.3.4",
5961
"geojson": "^0.5.0",
6062
"pbf": "^4.0.1",

src/data/contextual/ContextDataTileLoader.test.ts

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { classifyOvertureBarrier } from '../../features/barrier/overtureClassify
1010
import { classifyOvertureStructure } from '../../features/structure/overtureClassify';
1111
import { polygon, lineString, point } from '@turf/helpers';
1212

13+
const BOUNDS_POLYGON = polygon([
14+
[
15+
[-1, -1],
16+
[2, -1],
17+
[2, 2],
18+
[-1, 2],
19+
[-1, -1],
20+
],
21+
]);
22+
1323
describe('Overture classify functions', () => {
1424
it('classifies buildings with visual properties', () => {
1525
const geom = polygon([
@@ -134,12 +144,12 @@ describe('Overture classify functions', () => {
134144
],
135145
]).geometry;
136146

137-
const lake = classifyOvertureWater('w1', { class: 'lake' }, geom, {
138-
minLng: -1,
139-
minLat: -1,
140-
maxLng: 2,
141-
maxLat: 2,
142-
});
147+
const lake = classifyOvertureWater(
148+
'w1',
149+
{ class: 'lake' },
150+
geom,
151+
BOUNDS_POLYGON
152+
);
143153

144154
expect(lake!.type).toBe('lake');
145155
expect(lake!.isArea).toBe(true);
@@ -152,12 +162,12 @@ describe('Overture classify functions', () => {
152162
[1, 1],
153163
]).geometry;
154164

155-
const river = classifyOvertureWater('w2', { class: 'river' }, geom, {
156-
minLng: -1,
157-
minLat: -1,
158-
maxLng: 2,
159-
maxLat: 2,
160-
});
165+
const river = classifyOvertureWater(
166+
'w2',
167+
{ class: 'river' },
168+
geom,
169+
BOUNDS_POLYGON
170+
);
161171

162172
expect(river!.type).toBe('river');
163173
expect(river!.isArea).toBe(false);
@@ -188,7 +198,7 @@ describe('Overture classify functions', () => {
188198
'v1',
189199
{ class: 'forest', height: 25 },
190200
geom,
191-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
201+
BOUNDS_POLYGON
192202
);
193203

194204
expect(forest!.type).toBe('forest');
@@ -207,12 +217,11 @@ describe('Overture classify functions', () => {
207217
],
208218
]).geometry;
209219

210-
const bounds = { minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 };
211220
const landuse = classifyOvertureLanduse(
212221
'l1',
213222
{ class: 'residential' },
214223
geom,
215-
bounds
224+
BOUNDS_POLYGON
216225
);
217226

218227
expect(landuse).not.toBeNull();
@@ -436,7 +445,7 @@ describe('Overture classify functions', () => {
436445
'w3',
437446
{ class: 'stream', is_intermittent: true },
438447
geom,
439-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
448+
BOUNDS_POLYGON
440449
);
441450

442451
expect(water!.intermittent).toBe(true);
@@ -529,7 +538,7 @@ describe('Overture classify functions', () => {
529538
}),
530539
},
531540
geom,
532-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
541+
BOUNDS_POLYGON
533542
);
534543

535544
expect(veg!.leafType).toBe('broadleaved');
@@ -556,7 +565,7 @@ describe('Overture classify functions', () => {
556565
source_tags: { leaf_type: 'needleleaved', circumference: '2.1' },
557566
},
558567
geom,
559-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
568+
BOUNDS_POLYGON
560569
);
561570

562571
expect(veg!.leafType).toBe('needleleaved');
@@ -576,12 +585,12 @@ describe('Overture classify functions', () => {
576585
],
577586
]).geometry;
578587

579-
const veg = classifyOvertureVegetation('v-st3', { class: 'grass' }, geom, {
580-
minLng: -1,
581-
minLat: -1,
582-
maxLng: 2,
583-
maxLat: 2,
584-
});
588+
const veg = classifyOvertureVegetation(
589+
'v-st3',
590+
{ class: 'grass' },
591+
geom,
592+
BOUNDS_POLYGON
593+
);
585594

586595
expect(veg!.leafType).toBeUndefined();
587596
expect(veg!.leafCycle).toBeUndefined();
@@ -604,7 +613,7 @@ describe('Overture classify functions', () => {
604613
'v-st4',
605614
{ class: 'scrub', source_tags: '{not valid json' },
606615
geom,
607-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
616+
BOUNDS_POLYGON
608617
);
609618

610619
expect(veg!.leafType).toBeUndefined();
@@ -629,7 +638,7 @@ describe('Overture classify functions', () => {
629638
source_tags: { diameter_crown: 'wide', leaf_type: 'broadleaved' },
630639
},
631640
geom,
632-
{ minLng: -1, minLat: -1, maxLng: 2, maxLat: 2 }
641+
BOUNDS_POLYGON
633642
);
634643

635644
expect(veg!.crownDiameter).toBeUndefined();

0 commit comments

Comments
 (0)