Skip to content

Commit f093628

Browse files
committed
fix(boolean-contains): allow boundary points in MultiPoint-in-MultiPolygon check
1 parent 83a9b84 commit f093628

3 files changed

Lines changed: 55 additions & 10 deletions

File tree

packages/turf-boolean-contains/index.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,27 @@ function isPointInMultiPolygon(multiPolygon: MultiPolygon, point: Point) {
141141
* @private
142142
* @param {MultiPolygon} multiPolygon MultiPolygon geometry
143143
* @param {MultiPoint} multiPoint MultiPoint geometry
144-
* @returns {boolean} true if every point is inside the interior of some polygon in the MultiPolygon
144+
* @returns {boolean} true if no point is outside the MultiPolygon and at least one point is in the interior of some polygon
145145
*/
146146
function isMultiPointInMultiPolygon(
147147
multiPolygon: MultiPolygon,
148148
multiPoint: MultiPoint
149149
) {
150+
let oneInside = false;
150151
for (const coord of multiPoint.coordinates) {
151-
const pointInside = multiPolygon.coordinates.some((polyCoords) =>
152-
booleanPointInPolygon(
153-
coord,
154-
{ type: "Polygon", coordinates: polyCoords },
155-
{ ignoreBoundary: true }
156-
)
157-
);
158-
if (!pointInside) {
152+
// All points must be inside the MultiPolygon (boundary OK)
153+
if (!booleanPointInPolygon(coord, multiPolygon)) {
159154
return false;
160155
}
156+
// Track if at least one point is strictly in the interior
157+
if (!oneInside) {
158+
oneInside = booleanPointInPolygon(coord, multiPolygon, {
159+
ignoreBoundary: true,
160+
});
161+
}
161162
}
162-
return true;
163+
// At least one point must be in the interior (not just on boundary)
164+
return oneInside;
163165
}
164166

165167
/**
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "MultiPolygon",
9+
"coordinates": [
10+
[
11+
[
12+
[0, 0],
13+
[10, 0],
14+
[10, 10],
15+
[0, 10],
16+
[0, 0]
17+
]
18+
],
19+
[
20+
[
21+
[20, 0],
22+
[30, 0],
23+
[30, 10],
24+
[20, 10],
25+
[20, 0]
26+
]
27+
]
28+
]
29+
}
30+
},
31+
{
32+
"type": "Feature",
33+
"properties": {},
34+
"geometry": {
35+
"type": "MultiPoint",
36+
"coordinates": [
37+
[0, 5],
38+
[20, 5]
39+
]
40+
}
41+
}
42+
]
43+
}

packages/turf-boolean-contains/test/false/MultiPolygon/MultiPoint/MultiPointOneOnBoundary.geojson renamed to packages/turf-boolean-contains/test/true/MultiPolygon/MultiPoint/MultiPointOneOnBoundary.geojson

File renamed without changes.

0 commit comments

Comments
 (0)