Golf _rast

This commit is contained in:
Pyrex 2022-12-22 18:42:44 -08:00
parent ed25ef0f94
commit 1be4846698

View File

@ -103,13 +103,14 @@ end
function _rast(
x0,y0,x1,y1
xs,ys,x0,y0,x1,y1
)
local dx=abs(x1-x0)
local dy=abs(y1-y0)
local x=x0
local y=y0
local function _add()
local n=#xs
if (n==0 or xs[n]!=x0 or ys[n]!=y0) add(xs,x0) add(ys,y0)
end
local dx,dy=abs(x1-x0),abs(y1-y0)
local sx=-1
local sy=-1
if (x0<x1) sx=1
@ -118,27 +119,22 @@ function _rast(
local done=false,err
if dx>dy then
err=dx/2.0
return function()
if (done) return
if (x==x1) done=true return x1,y1
local oldx,oldy=x,y
while x0!=x1 do
_add()
err-=dy
if (err<0) y+=sy err+=dx
x+=sx
return oldx,oldy
if (err<0) y0+=sy err+=dx
x0+=sx
end
else
err=dy/2.0
return function()
if (done) return
if (y==y1) done=true return x1,y1
local oldx,oldy=x,y
while y0!=y1 do
_add()
err-=dx
if (err<0) x+=sx err+=dy
y+=sy
return oldx,oldy
if (err<0) x0+=sx err+=dy
y0+=sy
end
end
_add()
end
-->8
@ -1199,12 +1195,7 @@ function rope:_check_sane()
local n1=n0.next
if (n1==nil) break
for qx,qy in _rast(flr(n0.ax*2),flr(n0.ay*2),flr(n1.ax*2),flr(n1.ay*2)) do
if not (qx==qxs[#qxs] and qy==qys[#qys]) then
add(qxs,qx)
add(qys,qy)
end
end
_rast(qxs,qys,flr(n0.ax*2),flr(n0.ay*2),flr(n1.ax*2),flr(n1.ay*2))
n0=n1
end