Created
June 25, 2014 16:47
-
-
Save ShadowNinja/2125559927df5a26be02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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