Rectangle in a grid - I need help on the edge cases
snippet in lua

Rectangle in a grid - I need help on the edge cases

user2958

local function _toGridBox(l, t, w, h)
  local gl = math.floor(l / _cellSize)
  local gt = math.floor(t / _cellSize)
  local gr = math.ceil((l+w) / _cellSize)
  local gb = math.ceil((t+h) / _cellSize)
  return gl, gt, gr-gl, gb-gt  -- return top,left,cells to the right, cells to bottom
end