function isPointInsidePolygon(point, vs) {
const ε = 1e-20;
const [x, y] = point;
let inside = false;
for (let i = 0, j = vs.length - 1; i < vs.length; j = i++) {
const xi = vs[i][0], yi = vs[i][1];
const xj = vs[j][0], yj = vs[j][1];
const isPointWithinLineLimits = ((xi<=x && x<=xj) && (yi<=y && y<=yj))
|| ((xi>=x && x>=xj) && (yi>=y && y>=yj));
const dist = (x) * (yj - yi) - (y) * (xj - xi) + xj * yi - yj * xi;
const isPointInLine = Math.abs(dist) < ε;
if (isPointInLine && isPointWithinLineLimits) {
return true;
}
const isPointInTheRightHeigth = ((yi > y) != (yj > y));
const isPointToTheLeftOfLine = (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
const intersect = isPointInTheRightHeigth && isPointToTheLeftOfLine;
if (intersect) inside = !inside;
}
return inside;
}