mirror of
https://github.com/rastapasta/mapscii.git
synced 2024-11-21 23:53:08 +01:00
📐 adding utils.pointInPolygon
This commit is contained in:
parent
bfe6abadd7
commit
22907f4168
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user