Ray-casting algorithm: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, optimized a function.
(If Px is equal or bigger than segment's maximum x, then it should return "false" because It is already checked that Py is below Bx and above Ax. And we assume that point cannot be on the segment)
m (→‎{{header|REXX}}: added/changed comments and whitespace, optimized a function.)
Line 3,104:
return # // 2 /*ODD is inside. EVEN is outside.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
intersect: procedure expose point. poly.; parse arg ?,s; sp=s + 1
epsilon= '1e' || (-digits() %2); infinity= "1e" || (digits() *2)
Px=point.?.x; Ax=poly.s.x; Ay=poly.s.y
Line 3,112:
if Py<Ay | Py>By | Px>max(Ax, Bx) then return 0
if Px<min(Ax, Bx) then return 1
if Ax\=Bx then m_redred = (By-Ay) / (Bx-Ax)
else m_redred = infinity
if Ax\=Px then m_blue= return (Py-Ay) / (Px-Ax) >= red
return else return 1
return m_blue >= m_red
/*──────────────────────────────────────────────────────────────────────────────────────*/
points: wx=0; wy=0; do j=1 for arg(); parse value arg(j) with xx yy
Line 3,129 ⟶ 3,128:
do j=1 for arg(); n=n + 1; parse value arg(j) with xx yy
call value @ || n'.X', xx ; call value @ || n".Y", yy
if n//2 then iterate; n=n + 1 /*Inside? Then skip this point.*/
call value @ || n'.X', xx ; call value @ || n".Y", yy
end /*j*/
returnn=n + 1 /*POLY.0 is # segments(sides).*/
n=n + 1
call value @ || n'.X', Fx; call value @ || n".Y", Fy; call value @'0', n
return m_blue >= m_red
return /*POLY.0 is # segments(sides).*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
test: say; do k=1 for point.0; w=wx + wy + 2