package.flat.js Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of point-in-polygon Show documentation
Show all versions of point-in-polygon Show documentation
determine if a point is inside a polygon with a ray intersection counting algorithm
The newest version!
module.exports = function pointInPolygonFlat (point, vs, start, end) {
var x = point[0], y = point[1];
var inside = false;
if (start === undefined) start = 0;
if (end === undefined) end = vs.length;
var len = (end-start)/2;
for (var i = 0, j = len - 1; i < len; j = i++) {
var xi = vs[start+i*2+0], yi = vs[start+i*2+1];
var xj = vs[start+j*2+0], yj = vs[start+j*2+1];
var intersect = ((yi > y) !== (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};