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

[Bug] Returning false positives for points that are outside the polygon #2

Open
aa-cee opened this issue Feb 2, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@aa-cee
Copy link

aa-cee commented Feb 2, 2024

Describe the bug

The isPointInPolygon() flags points that lie to the left of the polygon as point within the polygon in certain cases.

To Reproduce

Steps to reproduce the behavior:

  1. Define a polygon with at least one vertical edge.
  2. Check for any point that lies outside and to the left of the polygon such that its y coordinate takes any value that is within the maximum and minimum y values of the polygon vertices.
  3. The isPointInPolygon() will return true.
  4. This is because the slope of the vertical edge becomes positive or negative infinity and will result in the value of x coordinate of the point where the ray intercepts the edge to be NaN.

Expected behavior

The isPointInPolygon() should return false.

@aa-cee aa-cee added the bug Something isn't working label Feb 2, 2024
@dodgog
Copy link

dodgog commented Feb 15, 2024

Same issue here.

Here is a sample polygon that gets a false positive for point (375.3548625134937, 806.9957936810772).

 (470.78502058654664, 731.6176660267478),
    (463.17644379366715, 732.5848829087928),
    (456.341556501049, 733.0362542873044),
    (449.3132468333655, 733.745522165903),
    (442.86525679423715, 734.9061614230133),
    (436.3527926300871, 737.1630183155712),
    (429.13106058733825, 743.224216107928),
    (421.1355602892894, 753.2832296785082),
    (413.9783023715624, 765.6635742666681),
    (407.0789409539225, 780.9455169976036),
    (400.95337404326216, 797.0012542355188),
    (397.85832727374157, 811.4449808378121),
    (399.47031165768385, 820.0209320228139),
    (404.886636941425, 826.5979753187041),
    (413.59140511807254, 832.6591731110609),
    (424.3595553088536, 836.4635665142189),
    (436.09489612999994, 837.2373085178394),
    (448.6684530797886, 833.8198123681711),
    (462.33817516166573, 823.4384281724822),
    (475.2986293649442, 807.5761133096323),
    (485.035114800338, 791.3269536966518),
    (489.09729969686487, 777.3990725978919),
    (486.84054781102526, 765.3411511382001),
    (482.2624649076059, 755.2821375676199),

@aa-cee
Copy link
Author

aa-cee commented Feb 15, 2024

Please check out my fork
This might work for your use case.

@dodgog
Copy link

dodgog commented Feb 15, 2024

Please check out my fork This might work for your use case.

Thank you so much! I've switched to using turf, in order to have future maintainability. They have a decent PIP library https://pub.dev/packages/turf_pip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants