Skip to content

Commit 2e42938

Browse files
committed
@turf/boolean-contains: allow boundary points in MultiPoint containment checks
1 parent 106a956 commit 2e42938

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

packages/turf-boolean-contains/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,21 @@ function isMultiPointOnLine(lineString: LineString, multiPoint: MultiPoint) {
157157
}
158158

159159
function isMultiPointInPoly(polygon: Polygon, multiPoint: MultiPoint) {
160+
let oneInside = false;
160161
for (const coord of multiPoint.coordinates) {
161-
if (!booleanPointInPolygon(coord, polygon, { ignoreBoundary: true })) {
162+
// All points must be inside polygon (boundary OK)
163+
if (!booleanPointInPolygon(coord, polygon)) {
162164
return false;
163165
}
166+
// Track if at least one point is strictly in the interior
167+
if (!oneInside) {
168+
oneInside = booleanPointInPolygon(coord, polygon, {
169+
ignoreBoundary: true,
170+
});
171+
}
164172
}
165-
return true;
173+
// At least one point must be in the interior (not just on boundary)
174+
return oneInside;
166175
}
167176

168177
function isLineOnLine(lineString1: LineString, lineString2: LineString) {

packages/turf-boolean-contains/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"contributors": [
77
"Rowan Winsemius <@rowanwins>",
88
"Denis Carriere <@DenisCarriere>",
9-
"Samuel Arbibe <@samuelarbibe>"
9+
"Samuel Arbibe <@samuelarbibe>",
10+
"Espen Hovlandsdal <@rexxars>"
1011
],
1112
"license": "MIT",
1213
"bugs": {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [
4+
{
5+
"type": "Feature",
6+
"properties": {},
7+
"geometry": {
8+
"type": "Polygon",
9+
"coordinates": [
10+
[
11+
[0, 0],
12+
[1, 0],
13+
[1, 1],
14+
[0, 1],
15+
[0, 0]
16+
]
17+
]
18+
}
19+
},
20+
{
21+
"type": "Feature",
22+
"properties": {},
23+
"geometry": {
24+
"type": "MultiPoint",
25+
"coordinates": [
26+
[0.5, 0.5],
27+
[1, 1]
28+
]
29+
}
30+
}
31+
]
32+
}

0 commit comments

Comments
 (0)