Code: Select all
local function get_center(ax,ay, bx,by)
local cx = ax + (bx - ax)/2
local cy = ay>by and (by + (ay - by)/2) or (ay + (by - ay)/2)
return floor(cx), floor(cy)
end
local function do_stuff( ox, oy, ax, ay, bx, by) -- 'o' = point / 'a' and 'b' = line ends
local cx,cy = get_center( ax,ay, bx,by)
if cx == ox and cy <= oy then
return vec(cx,cy)
end
local up = ay>by --did you know that IRL the number of slopes going down is = the number of slopes going up?
local u,s
local sx,sy,ex,ey
if up then
if oy>=cy and ox>=cx then return vec(cx,cy) end
if (oy<cy and ox<=cx) or (oy==cy and ox<cx) then return false end
u = oy<cy and ox>cx --ac/d
s = oy>cy and ox<cx --ab/e
if u then
sx, sy = cx, cy
ex, ey = bx, by
elseif s then
sx, sy = ax, ay
ex, ey = cx, cy
end
else
if oy>=cy and ox<=cx then return vec(cx,cy) end
if (oy<cy and ox>=cx) or (oy==cy and ox>cx) then return false end
u = oy<cy and ox<cx --ac/e
s = oy>cy and ox>cx --ab/d
if u then
sx, sy = ax, ay
ex, ey = cx, cy
elseif s then
sx, sy = cx, cy
ex, ey = bx, by
end
end
return do_stuff( ox, oy, sx, sy, ex, ey) --keep doing it until its on or off
end
is it ok if it works?
do you know a better way?
inb4 google it
i just want to know how you guys handle this.