diff --git a/src/utils.coffee b/src/utils.coffee index 16541bb..31dcabe 100644 --- a/src/utils.coffee +++ b/src/utils.coffee @@ -6,6 +6,17 @@ ### utils = + # Based on W. Randolph Franklin (WRF)'s Point Inclusion in Polygon Test + # https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html + pointInPolygon: (polygon, point) -> + inside = false + j = polygon.length-1 + for i in [0...polygon.length] + if (polygon[i][1]>point[1]) isnt (polygon[j][1]>point[1]) and + point[0] < (polygon[j][0]-polygon[i][0]) * (point[1]-polygon[i][1]) / (polygon[j][1]-polygon[i][1]) + polygon[i][0] + inside = !inside + j = i + deg2rad: (angle) -> # (angle / 180) * Math.PI angle * 0.017453292519943295