Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/turf-boolean-contains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/turf-boolean-contains/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"contributors": [
"Rowan Winsemius <@rowanwins>",
"Denis Carriere <@DenisCarriere>",
"Samuel Arbibe <@samuelarbibe>"
"Samuel Arbibe <@samuelarbibe>",
"Espen Hovlandsdal <@rexxars>"
],
"license": "MIT",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
]
}
}
]
}