Point in the Hit Test polygon in JavaScript (Chrome error)

I am working on a game written in javaScript / jQuery. Part of my code draws a random polygon (island) on a tile grid. I need to check if the point is inside the polygon.

I am using point intersection in a polygon script, which I found in several places on Qaru (the original is here ). This works fine in Firefox. In Chrome, there are dots inside the polygon, which the script says is not inside it.

In Firefox: enter image description here

In Chrome (the island is different in that they are randomly generated): enter image description here

Please see the source here, especially the pointPolygonIntersect function: Point in polygon collision test

Can anyone understand why this is happening? The original script is in C and I am using a version of JavaScript - could this be the cause of the problem?

+4
source share
2 answers

Choose an island and stick to it. Track the code in both browsers and see where they differ. There is no reason to deal with an accident that you can easily remove ...

+2
source

I quickly looked at him. Failed to track application flow but looks weird

c = !c; 

line of code. Why don't you just set it to true or don't directly return true if you meet the conditions for the first time? I assume that chrome goes over to "true" and then inverts it next time within x / y.

I am not familiar with Raphael or SVG, but it seems your polygons are squares, so you can do a simple test

 //original found here http://www.gamedev.net/topic/483716-point-inside-of-rectangle/ function inside( x, y, l, r, b, t ){ //x,y are the point, l,r,b,t are the extents of the rectangle return x > l && x < r && y > b && y < t; } 
0
source

All Articles