Skip to content

Commit 8765bc6

Browse files
committed
perf(boolean-intersects): replace redundant flattenEach with booleanDisjoint
`booleanDisjoint` already compares every flattened geometry pair internally. I also removed @turf/meta and @turf/helpers from the package's dependencies since nothing in the package imports them anymore (helpers was unused even before this change). Benchmarks show between +50% and +100% improvement in speed on MacBook M4 Pro.
1 parent 50ff666 commit 8765bc6

3 files changed

Lines changed: 3 additions & 21 deletions

File tree

packages/turf-boolean-intersects/index.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Feature, Geometry } from "geojson";
22
import { booleanDisjoint } from "@turf/boolean-disjoint";
3-
import { flattenEach } from "@turf/meta";
43

54
/**
65
* Boolean-intersects returns (TRUE) if the intersection of the two geometries is NOT an empty set.
@@ -36,18 +35,9 @@ function booleanIntersects(
3635
ignoreSelfIntersections?: boolean;
3736
} = {}
3837
) {
39-
let bool = false;
40-
flattenEach(feature1, (flatten1) => {
41-
flattenEach(feature2, (flatten2) => {
42-
if (bool === true) {
43-
return true;
44-
}
45-
bool = !booleanDisjoint(flatten1.geometry, flatten2.geometry, {
46-
ignoreSelfIntersections,
47-
});
48-
});
49-
});
50-
return bool;
38+
// booleanDisjoint already compares every flattened geometry pair, so
39+
// intersects is simply its negation.
40+
return !booleanDisjoint(feature1, feature2, { ignoreSelfIntersections });
5141
}
5242

5343
export { booleanIntersects };

packages/turf-boolean-intersects/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
},
6868
"dependencies": {
6969
"@turf/boolean-disjoint": "workspace:*",
70-
"@turf/helpers": "workspace:*",
71-
"@turf/meta": "workspace:*",
7270
"@types/geojson": "catalog:",
7371
"tslib": "catalog:"
7472
}

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)