static/js/algorithm.js
/**
 * Check if a point is within a polygon.
 * @function pnpoly
 * @param {number} x - x-coordinate of point
 * @param {number} y - y-coordinate of point
 * @param {{x: number, y: number}[]} polygon - x- and y-coordinates of vertices
 * of polygon
 * @returns {boolean} whether point is within polygon
 * @description Reimplemented following:
 * PNPOLY - Point Inclusion in Polygon Test
 * @author W Randolph Franklin:
 * {@link https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html}
 * @license MIT license
 * @see licenses/pnpoly.txt
 */
Check if a point is within a polygon.
Check if a point is within a polygon .
function pnpoly(x, y, polygon) {
  let res = false;
  const n = polygon.length;
  let xi, yi, xj, yj;
  for (let i = 0, j = n - 1; i < n; j = i++) {
    xi = polygon[i].x;
    yi = polygon[i].y;
    xj = polygon[j].x;
    yj = polygon[j].y;
    if (((yi > y) != (yj > y)) &&
      (x < (xj - xi) * (y - yi) / (yj - yi) + xi)) {
      res = !res;
    }
  }
  return res;
}
function pnpoly ( x , y , polygon ) { let res = false ; const n = polygon . length ; let xi , yi , xj , yj ; for ( let i = 0 , j = n - 1 ; i < n ; j = i ++ ) { xi = polygon [ i ] . x ; yi = polygon [ i ] . y ; xj = polygon [ j ] . x ; yj = polygon [ j ] . y ; if ( ( ( yi > y ) != ( yj > y ) ) && ( x < ( xj - xi ) * ( y - yi ) / ( yj - yi ) + xi ) ) { res = ! res ; } } return res ; }
Check if a point is within a polygon.
Check if a point is within a polygon .