tmpvar/polygon.js — pull request #2 by cbupp (2014-02-15 19:16:11+00:00)
Title: Improved (or rather different... based on opinion) Point in Polygon

While attempting to fix a failing unit test (https://github.com/cbupp/polygon.clip.js/commit/ee5ed154f9df798ac9059f31a934966aca4bcad2) in the `polygon.clip` library, I discovered that the polygon's `containsPoint` method wasn't always correct.

I added a failing unit test, and then started digging in the code.

I've updated the containsPoint to a fairly well used `PNPoly` algorithm: http://www.ecse.rpi.edu/~wrf/Research/Short_Notes/pnpoly.html

Though, doing so breaks some of your unit tests that are checking for boundary point inclusions. Specifically, the PNPoly considers: "a point is within a polygon if and only if its y-value is within the range of the projected polygon on the y-axis and the x-value of the point is below odd number of polygon edges.".

I'd argue that in the wild (i.e. the way I'm using it) a point will rarely be exactly on the polygon... but if it is... shrug...

BUT: It's your library, so if you need point inclusion to work a certain way, feel free to reject this pull request.

Thanks!