Skip to content

Instantly share code, notes, and snippets.

@ShadowNinja
Created June 25, 2014 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShadowNinja/2125559927df5a26be02 to your computer and use it in GitHub Desktop.
Save ShadowNinja/2125559927df5a26be02 to your computer and use it in GitHub Desktop.
--- Iterator over positions of a cube.
-- @param pos Reference to starting position (lowest x, y, and z coordinates). Note that this is overwritten.
-- @param size Size of the cube
local function iterCube(pos, size)
local startx, starty = pos.x, pos.y
local endx, endy, endz = pos.x + size, pos.y + size, pos.z + size
pos.x = pos.x - 1
return function()
if pos.x < endx then
pos.x = pos.x + 1
else
pos.x = startx
if pos.y < endy then
pos.y = pos.y + 1
else
pos.y = starty
if pos.z < endz then
pos.z = pos.z + 1
else
return nil
end
end
end
return pos
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment