Closed Kcnarf closed 4 years ago
polygonContains is not robust, so it’s not guaranteed to return the correct result in edge cases like this. We could tweak the algorithm to make it perform better in special cases, but only at the expense of complexity and speed. I don’t think we want to go all the way to making it robust.
See https://observablehq.com/@tmcw/understanding-point-in-polygon for an explanation of the algorithm.
Thanks for the response and the provided links.
I discovered the use case while debugging some tests I did for d3-weighted-voronoi plugin, which sometimes were failing. I was positioning a site at the [1,1] vertex, considered outside of the unit square, and hence re-position the site in a random fashion (hence the rare failure).
Closing the issue as the non-robustness seems assumed.
PS: perhaps a hint in the documentation may help.
In Runkit => https://runkit.com/embed/tht1jbzi6iqq
Imho, all the verteces of the polygon should be either inside or outside.