main #12

Merged
kistaro merged 20 commits from pyrex/chameleonic:main into main 2022-12-23 06:38:45 +00:00
Showing only changes of commit f3a0b04cc4 - Show all commits

View File

@ -53,21 +53,19 @@ function linefill(ax,ay,bx,by,r,c)
local dx,dy=bx-ax,by-ay
-- avoid overflow
-- credits: https://www.lexaloffle.com/bbs/?tid=28999
local d=max(abs(dx),abs(dy))
local n=min(abs(dx),abs(dy))/d
local n,d=_mnmx(abs(dx),abs(dy))
n/=d
d*=sqrt(n*n+1)
if(d<0.001) return
local ca,sa=dx/d,-dy/d
-- polygon points
local s={
{0,-r},{d,-r},{d,r},{0,r}
}
local u,v,spans=s[4][1],s[4][2],{}
local x0,y0=ax+u*ca+v*sa,ay-u*sa+v*ca
local s={{0,-r},{d,-r},{d,r},{0,r}}
local spans={}
local function calcxy(u,v) return ax+u*ca+v*sa,ay-u*sa+v*ca end
local x0,y0=calcxy(0,r)
for i=1,4 do
local u,v=s[i][1],s[i][2]
local x1,y1=ax+u*ca+v*sa,ay-u*sa+v*ca
local x1,y1=calcxy(unpack(s[i]))
local _x1,_y1=x1,y1
if(y0>y1) x0,y0,x1,y1=x1,y1,x0,y0
local dx=(x1-x0)/(y1-y0)
@ -78,11 +76,8 @@ function linefill(ax,ay,bx,by,r,c)
for y=y0\1+1,min(y1\1,127) do
-- open span?
local span=spans[y]
if span then
rectfill(x0,y,span,y)
else
spans[y]=x0
end
if (span) rectfill(x0,y,span,y)
spans[y]=x0
x0+=dx
end
x0,y0=_x1,_y1