1function insidePoly(poly, pointx, pointy) {
2 var i, j;
3 var inside = false;
4 for (i = 0, j = poly.length - 1; i < poly.length; j = i++) {
5 if(((poly[i].y > pointy) != (poly[j].y > pointy)) && (pointx < (poly[j].x-poly[i].x) * (pointy-poly[i].y) / (poly[j].y-poly[i].y) + poly[i].x) ) inside = !inside;
6 }
7 return inside;
8}
9