Skip to content

Commit

Permalink
Improve performances of booleanPointInPolygon with MultiPolygons
Browse files Browse the repository at this point in the history
Optimize booleanPointInPolygon to return "true" as soon as one polygon contains the point instead of looping over all the polygons
  • Loading branch information
Pitouli authored Jan 18, 2025
1 parent 8410246 commit 2049430
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/turf-boolean-point-in-polygon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ function booleanPointInPolygon<
if (type === "Polygon") {
polys = [polys];
}
let result = false;

for (var i = 0; i < polys.length; ++i) {
const polyResult = pip(pt, polys[i]);
if (polyResult === 0) return options.ignoreBoundary ? false : true;
else if (polyResult) result = true;
else if (polyResult) return true;
}

return result;
return false;
}

/**
Expand Down

0 comments on commit 2049430

Please sign in to comment.