Use winding number algorithm for linearRingContainsXY #6078

Merged
merged 2 commits into from Dec 1, 2016

Projects

None yet

3 participants

@bjornharrtell
Contributor

Found out about this algorithm in another project and it seems nice so I propose to replace the old one.

@bartvanandel

Why? Is it faster?

@bjornharrtell
Contributor

Is is slightly faster in some cases and as fast in all cases according to the author. It can also handle non simple polygons.

Sources:
https://en.wikipedia.org/wiki/Point_in_polygon
http://geomalgorithms.com/a03-_inclusion.html

@bartvanandel

Interesting! I think your latter point is even more important: for polygons with self-intersections the currently used Crossing Number algorithm will give wrong answers in the parts where the polygon overlaps with itself an even number of times. The Winding Number algorithm does not have this problem.

@marcjansen
Member

hey @bjornharrtell, any chance of adding tests for non simple polygons?

@bjornharrtell
Contributor

You got it @marcjansen. :)

@marcjansen
Member

Thanks for adding the tests, @bjornharrtell. Is it just me or are these tests passing with or without changing the algorithm?

I still think this looks good, but just want to confirm.

bjornharrtell added some commits Nov 27, 2016
@bjornharrtell bjornharrtell Add test case for ol.geom.flat.contains 6c64418
@bjornharrtell bjornharrtell Use winding number algorithm for linearRingContainsXY
656af72
@bjornharrtell
Contributor

The test returns true for point inside an overlap of a non-simple polygon should fail with the existing algorithm. I just cherry picked d344098 on master and it fails as expected. Though I noticed that I had forgot to change the description of the test cases, I've fixed that now.

@marcjansen
Member

Thanks for this @bjornharrtell.

@marcjansen marcjansen merged commit bdeaafc into openlayers:master Dec 1, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.05%) to 86.636%
Details
@bjornharrtell bjornharrtell deleted the bjornharrtell:windingnumber branch Dec 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment