diff --git a/packages/turf-boolean-contains/index.ts b/packages/turf-boolean-contains/index.ts index 1c5c177e5c..53f8d9db18 100644 --- a/packages/turf-boolean-contains/index.ts +++ b/packages/turf-boolean-contains/index.ts @@ -157,12 +157,21 @@ function isMultiPointOnLine(lineString: LineString, multiPoint: MultiPoint) { } function isMultiPointInPoly(polygon: Polygon, multiPoint: MultiPoint) { + let oneInside = false; for (const coord of multiPoint.coordinates) { - if (!booleanPointInPolygon(coord, polygon, { ignoreBoundary: true })) { + // All points must be inside polygon (boundary OK) + if (!booleanPointInPolygon(coord, polygon)) { return false; } + // Track if at least one point is strictly in the interior + if (!oneInside) { + oneInside = booleanPointInPolygon(coord, polygon, { + ignoreBoundary: true, + }); + } } - return true; + // At least one point must be in the interior (not just on boundary) + return oneInside; } function isLineOnLine(lineString1: LineString, lineString2: LineString) { diff --git a/packages/turf-boolean-contains/package.json b/packages/turf-boolean-contains/package.json index 3f61532d1b..54c39847ea 100644 --- a/packages/turf-boolean-contains/package.json +++ b/packages/turf-boolean-contains/package.json @@ -6,7 +6,8 @@ "contributors": [ "Rowan Winsemius <@rowanwins>", "Denis Carriere <@DenisCarriere>", - "Samuel Arbibe <@samuelarbibe>" + "Samuel Arbibe <@samuelarbibe>", + "Espen Hovlandsdal <@rexxars>" ], "license": "MIT", "bugs": { diff --git a/packages/turf-boolean-contains/test/true/MultiPoint/Polygon/MultiPointOneOnBoundaryOneInterior.geojson b/packages/turf-boolean-contains/test/true/MultiPoint/Polygon/MultiPointOneOnBoundaryOneInterior.geojson new file mode 100644 index 0000000000..c99916c0f4 --- /dev/null +++ b/packages/turf-boolean-contains/test/true/MultiPoint/Polygon/MultiPointOneOnBoundaryOneInterior.geojson @@ -0,0 +1,32 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [0, 0], + [1, 0], + [1, 1], + [0, 1], + [0, 0] + ] + ] + } + }, + { + "type": "Feature", + "properties": {}, + "geometry": { + "type": "MultiPoint", + "coordinates": [ + [0.5, 0.5], + [1, 1] + ] + } + } + ] +}