Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pointToPolygonDistance with hole return unsigned values #2824

Open
ata-electronics opened this issue Jan 20, 2025 · 2 comments · May be fixed by #2845
Open

pointToPolygonDistance with hole return unsigned values #2824

ata-electronics opened this issue Jan 20, 2025 · 2 comments · May be fixed by #2845
Assignees

Comments

@ata-electronics
Copy link

Hello,
The pointToPolygonDistance function return positive value for a point in polygon with an hole:

How to reproduce :
Use this file in https://turf-sandbox.netlify.app/
turfSandbox_scipt_pointToPolygonDistance.txt

Fix:
I think that the issue is on line 72 of file https://github.com/Turfjs/turf/blob/master/packages/turf-point-to-polygon-distance/index.ts
return Math.min(smallestInteriorDistance, Math.abs(exteriorDistance));
should be replaced by
return Math.max(smallestInteriorDistance*-1, exteriorDistance);

@smallsaucepan
Copy link
Member

Well done tracking that down @ata-electronics.

Would you mind explaining what was happening and how the different logic fixes the problem?

And also, do you have any idea why the existing test in multi-polygon.geojson didn't catch this issue?

@smallsaucepan smallsaucepan self-assigned this Jan 23, 2025
@LHBruneton-C2C
Copy link

Hello,

I've looked up this issue. I agree with @ata-electronics suggestion, and I can explain why.

You can have a look at this PR #2845

And the existing multi-polygon.geojson didn't catch this issue because it only happens with polygons. Multi-polygons are correctly re-signed on line 56 with the call to booleanPointInPolygon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants