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

polygonInPolygon return false with same polygon or polygon with same point #20

Open
justb opened this issue Feb 22, 2021 · 4 comments
Open
Labels
bug Something isn't working

Comments

@justb
Copy link

justb commented Feb 22, 2021

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 justb changed the title polygonInPolygon return false with two same polygons or polygonInPolygon return false with same polygon or same point Feb 22, 2021
@justb justb changed the title polygonInPolygon return false with same polygon or same point polygonInPolygon return false with same polygon or polygon with same point Feb 22, 2021
@HarryStevens
Copy link
Owner

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?

@lenikhilsingh
Copy link

yup, first option sounds fair enough @HarryStevens

@MengZhaoFly
Copy link

need this feature,

@HarryStevens
Copy link
Owner

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 HarryStevens added the bug Something isn't working label Aug 2, 2022
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

4 participants