I am working on a game written in javaScript / jQuery. Part of my code draws a random polygon (an island) on a tile grid. I need to check if a point is inside the polygon.
I am using a point-in-polygon intersection script which I found in several places on Stack Overflow (original here). This works fine in Firefox. In Chrome, there are points inside the polygon which the script says are not inside it.
In Firefox:
In Chrome (the island is different because they are randomly generated):
Please take a look at the source here, particularly the pointPolygonIntersect function: Point in Polygon Hit Test
Can anyone figure out why this is happening? The original script is in C, and I am using a JavaScript version - could this be causing the problem?
Pick an island and stick with it. Trace the code in both browsers and see where they differ. There's no reason to fight against the randomness that you can easily remove...