I'm trying to figure out how to make a supercover DDA algorithm. Or in other words, a DDA algorithm that will cover ALL grid points crossed by a line. See the image below.
The image was drawn by me and might not be 100% accurate but it shows the general idea. I also want to note the examples on the lower half of the image do not have integer start and end coordinates, this is necessary.
If you need to know, I intend to use this for line of sight ray casting.
I'm capable of implementing a typical DDA algorithm, but my problem is, how can I modify it to cover all points?
Thanks!
My current implementation of the DDA algorithm in Lua
function dline(x0,y0, x1,y1) -- floating point input
local dx = x1-x0
local dy = y1-y0
local s = math.max(math.abs(dx),math.abs(dy))
dx = dx/s
dy = dy/s
local x = x0
local y = y0
local i = 0
return function() -- iterator intended for a for loop
if i <= s then
local rx,ry = x,y
x = x+dx
y = y+dy
i = i+1
return rx,ry
end
end
end