micro-optimizations
This commit is contained in:
parent
d2ec1b39df
commit
812d32e70c
@ -22,28 +22,26 @@ function collides()
|
|||||||
|
|
||||||
-- x
|
-- x
|
||||||
if ldx==0 then
|
if ldx==0 then
|
||||||
local lx=lx0 -- which ==lx1
|
if (lx0<bx0 or lx0>bx1) return
|
||||||
if (lx<bx0 or lx>=bx1) return nil
|
|
||||||
else
|
else
|
||||||
local tx0=(bx0-lx0)/ldx
|
local tx0=(bx0-lx0)/ldx
|
||||||
local tx1=(bx1-lx0)/ldx
|
local tx1=(bx1-lx0)/ldx
|
||||||
|
if (tx0 > tx1) tx0,tx1=tx1,tx0
|
||||||
tmin=max(tmin,min(tx0,tx1))
|
if (tmin < tx0) tmin=tx0
|
||||||
tmax=min(tmax,max(tx0,tx1))
|
if (tmax > tx1) tmax=tx1
|
||||||
end
|
end
|
||||||
|
|
||||||
if ldy==0 then
|
if ldy==0 then
|
||||||
local ly=ly0 -- which ==ly1
|
if (ly0<by0 or ly0>by1) return
|
||||||
if (ly<by0 or ly>=by1) return nil
|
|
||||||
else
|
else
|
||||||
local ty0=(by0-ly0)/ldy
|
local ty0=(by0-ly0)/ldy
|
||||||
local ty1=(by1-ly0)/ldy
|
local ty1=(by1-ly0)/ldy
|
||||||
|
if (ty0 > ty1) ty0,ty1=ty1,ty0
|
||||||
tmin=max(tmin,min(ty0,ty1))
|
if (tmin < ty0) tmin=ty0
|
||||||
tmax=min(tmax,max(ty0,ty1))
|
if (tmax > ty1) tmax=ty1
|
||||||
end
|
end
|
||||||
|
|
||||||
if (tmax < tmin) return nil
|
if (tmax < tmin) return
|
||||||
return tmin,tmax
|
return tmin,tmax
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user