geometric
geometric copied to clipboard
polygonInPolygon return false with same polygon or polygon with same point
var poly1 = [[1,2], [215,1], [215,215]]; var poly2 = [[1,2], [215,1], [215,215]]; let res = geometric.polygonInPolygon(poly1, poly2) // false
// another situation var poly1 = [[1,2], [215,1], [214,214]]; var poly2 = [[1,2], [215,1], [215,215]]; let res = geometric.polygonInPolygon(poly1, poly2) // false
geometric.polygonInPolygon(polygonA, polygonB) currently returns false if points in polygonA lie on polygonB's edges, even if none of polygonA's points lie outside of polygonB. So the function should return false, even though that is not the result you want.
I can think of two possible fixes:
One would be to add a third parameter to the function which would be a boolean called, say, allowPointsOnEdges. It would default to false but you could set it to true when you want the function to return true if none of the points in polygonA fall outside of polygonB, even if some points in polygonA are on polygonB's edges.
The other would be to add a function to the library called, say, geometric.polygonNotOutsidePolygon, which would just be a more permissive version of geometric.polygonInPolygon in that it would return true if none of polygonA's points were outside of polygonB's points, even if some of polygonA's points lay on polygonB's edges.
My inclination is to go with the first option. What do you think?
yup, first option sounds fair enough @HarryStevens
need this feature,
Sorry I haven't had time to work on this. Everything one might need to try to resolve this is in this Observable notebook. I'm sure I'll get around to it eventually, but if someone wants to take a crack at it and send me a PR, that is likely to get this resolved sooner.