From 22907f4168621e09087fe6b1820089c6eb918f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Stra=C3=9Fburger?= Date: Wed, 28 Sep 2016 13:39:34 +0200 Subject: [PATCH] :triangular_ruler: adding utils.pointInPolygon --- src/utils.coffee | 11 +++++++++++ 1 file changed, 11 insertions(+) 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