Ray-casting algorithm: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace.
m (→‎{{header|REXX}}: added/changed comments and whitespace.)
Line 3,269:
if Ay>By then parse value Ax Ay Bx By with Bx By Ax Ay
if Py=Ay | Py=By then Py=Py + epsilon
if Py<Ay | Py>By | Px>max(Ax, Bx) then return 0
if Px<min(Ax, Bx) then return 1
if Ax\=Bx then red = (By-Ay) / (Bx-Ax)
else red = infinity
if Ax\=Px then return (Py-Ay) / (Px-Ax) >= red
return 1
/*──────────────────────────────────────────────────────────────────────────────────────*/
points: wx=0; wy=0; do j=1 for arg(); parse value arg(j) with xx yy
wx=max(wx, length(xx) ); call value 'POINT.'j".X", xx
wy=max(wy, length(yy) ); call value 'POINT.'j".Y", yy
end /*j*/
call value point.0, j-1 /*define the number of points. */
return /* [↑] adjust J (for DO loop)*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
poly: @= 'POLY.'; parse arg Fx Fy /* [↓] process the X,Y points.*/
n=0
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*/
n=n + 1 /*POLY.0 is # segments(sides).*/
call value @ || n'.X', Fx; call value @ || n".Y", Fy; call value @'0', n
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
test: say; do k=1 for point.0; w=wx + wy + 2 /*W, WX, WY ≡are w=wxvarious + wy + 2widths*/
say right(' ['arg(1)"] point:", 30),
right( right(point.k.x, wx)', 'right(point.k.y, wy), w) " is ",
right( word('outside inside', in$out(k) + 1), 7)
end /*k*/
return /* [↑] format the output nicely*/</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>