title: Supercover DDA algorithm
body: <p>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.</p>
  
  <p><img src="https://i.imgur.com/a9Nwq1O.png" title="Hosted by imgur.com" /></p>
  
  <p>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.</p>
  
  <p>If you need to know, I intend to use this for line of sight ray casting.</p>
  
  <p>I'm capable of implementing a typical DDA algorithm, but my problem is, how can I modify it to cover all points?</p>
  
  <p>Thanks!</p>
  
  <p>My current implementation of the DDA algorithm in Lua</p>
  
  <pre><code>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 &lt;= s then
        local rx,ry = x,y
        x = x+dx
        y = y+dy
        i = i+1
        return rx,ry
      end
    end
  end
  </code></pre>