// ray-casting algorithm based on // https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html module.exports = function pointInPolygonNested (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; for (var i = 0, j = len - 1; i < len; j = i++) { var xi = vs[i+start][0], yi = vs[i+start][1]; var xj = vs[j+start][0], yj = vs[j+start][1]; var intersect = ((yi > y) !== (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi); if (intersect) inside = !inside; } return inside; };