geometric icon indicating copy to clipboard operation
geometric copied to clipboard

polygonInPolygon return false with same polygon or polygon with same point

Open justb opened this issue 4 years ago • 4 comments

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

justb avatar Feb 22 '21 07:02 justb

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?

HarryStevens avatar Feb 27 '21 16:02 HarryStevens

yup, first option sounds fair enough @HarryStevens

lenikhilsingh avatar Mar 18 '21 05:03 lenikhilsingh

need this feature,

MengZhaoFly avatar May 21 '21 06:05 MengZhaoFly

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.

HarryStevens avatar May 27 '21 20:05 HarryStevens