Skip to content

Commit 9edc247

Browse files
Fix issue 2824 on turf-point-to-polygon-distance (#2845)
* add non-passing test fixture * make each step return correctly signed value * call booleanPointInPolygon one less time --------- Co-authored-by: James Beard <[email protected]>
1 parent 8ccda4a commit 9edc247

File tree

2 files changed

+420
-1
lines changed

2 files changed

+420
-1
lines changed

packages/turf-point-to-polygon-distance/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export function pointToPolygonDistance(
6969
// point is inside one of the holes?
7070
if (smallestInteriorDistance < 0) return Math.abs(smallestInteriorDistance);
7171
// find which is closer, the distance to the hole or the distance to the edge of the exterior
72-
return Math.min(smallestInteriorDistance, Math.abs(exteriorDistance));
72+
// at this stage, exteriorDistance is negative and smallestInteriorDistance is positive
73+
// but smallestInteriorDistance should be returned as negative
74+
// and min of positive values <=> max of negative values
75+
return Math.max(smallestInteriorDistance * -1, exteriorDistance);
7376
}
7477
// The actual distance operation - on a normal, hole-less polygon in meters
7578
const lines = polygonToLine(geom);

0 commit comments

Comments
 (0)