tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,28 @@
|
|||
Point = (@x,@y) ->
|
||||
|
||||
pointInPoly = (point,poly) ->
|
||||
segments = for pointA, index in poly
|
||||
pointB = poly[(index + 1) % poly.length]
|
||||
[pointA,pointB]
|
||||
intesected = (segment for segment in segments when rayIntesectsSegment(point,segment))
|
||||
intesected.length % 2 != 0
|
||||
|
||||
rayIntesectsSegment = (p,segment) ->
|
||||
[p1,p2] = segment
|
||||
[a,b] = if p1.y < p2.y
|
||||
[p1,p2]
|
||||
else
|
||||
[p2,p1]
|
||||
if p.y == b.y || p.y == a.y
|
||||
p.y += Number.MIN_VALUE
|
||||
|
||||
if p.y > b.y || p.y < a.y
|
||||
false
|
||||
else if p.x > a.x && p.x > b.x
|
||||
false
|
||||
else if p.x < a.x && p.x < b.x
|
||||
true
|
||||
else
|
||||
mAB = (b.y - a.y) / (b.x - a.x)
|
||||
mAP = (p.y - a.y) / (p.x - a.x)
|
||||
mAP > mAB
|
||||
Loading…
Add table
Add a link
Reference in a new issue