All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.flat.js Maven / Gradle / Ivy

Go to download

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;
};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy