d3 / d3-polygon

Geometric operations for two-dimensional polygons.
https://d3js.org/d3-polygon
ISC License
97 stars 25 forks source link

Flipping flag for contain #18

Closed MuhammadTaha closed 5 years ago

MuhammadTaha commented 5 years ago

I am working on geo coordinates and needed to check if the point is inside the polygon, what i found is an issue whenever the condition is met the inside flag is flipped in my case it is always showing me false.

https://github.com/d3/d3-polygon/blob/master/src/contains.js#L11

Shouldn't it be like if it matches once it should be considered inside.

mbostock commented 5 years ago

We’re not going to change the expected orientation of this method. If you are using spherical coordinates, you should probably be using d3.geoContains instead of d3-polygon. If you’re using planar (e.g., projected) coordinates that have the y-axis flipped, then you can negate the return value of d3.polygonContains or reverse the coordinates to get the desired behavior.