Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add empty VoxelArea class #35

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions voxelmanip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,73 @@ mineunit.export_object(VoxelManip, {
return obj
end,
})

local VoxelArea = {}

--* `getExtent()`: returns a 3D vector containing the size of the area formed by `MinEdge` and `MaxEdge`.
function VoxelArea:getExtent()
end

--* `getVolume()`: returns the volume of the area formed by `MinEdge` and `MaxEdge`.
function VoxelArea:getVolume()
end

--* `index(x, y, z)`: returns the index of an absolute position in a flat array starting at `1`.
-- * `x`, `y` and `z` must be integers to avoid an incorrect index result.
-- * The position (x, y, z) is not checked for being inside the area volume,
-- being outside can cause an incorrect index result.
-- * Useful for things like `VoxelManip`, raw Schematic specifiers, `PerlinNoiseMap:get2d`/`3dMap`, and so on.
function VoxelArea:index(x, y, z)
end

--* `indexp(p)`: same functionality as `index(x, y, z)` but takes a vector.
-- * As with `index(x, y, z)`, the components of `p` must be integers, and `p`
-- is not checked for being inside the area volume.
function VoxelArea:indexp(p)
end

--* `position(i)`: returns the absolute position vector corresponding to index `i`.
function VoxelArea:position(i)
end

--* `contains(x, y, z)`: check if (`x`,`y`,`z`) is inside area formed by `MinEdge` and `MaxEdge`.
function VoxelArea:contains(x, y, z)
end

--* `containsp(p)`: same as above, except takes a vector
function VoxelArea:containsp(p)
end

--* `containsi(i)`: same as above, except takes an index `i`
function VoxelArea:containsi(i)
end

--* `iter(minx, miny, minz, maxx, maxy, maxz)`: returns an iterator that returns indices.
-- * from (`minx`,`miny`,`minz`) to (`maxx`,`maxy`,`maxz`) in the order of `[z [y [x]]]`.
function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz)
end

--* `iterp(minp, maxp)`: same as above, except takes a vector
function VoxelArea:iterp(minp, maxp)
end

--A helper class for voxel areas.
--It can be created via `VoxelArea:new{MinEdge = pmin, MaxEdge = pmax}`.
--The coordinates are *inclusive*, like most other things in Minetest.
function VoxelArea:new(bounds)
local obj = {}
assert(type(bounds) == "table", "VoxelArea: requires table as argument. Argument type was "..type(bounds))
obj._minp = bounds.MinEdge
assert(type(obj._minp) == "table", "VoxelArea: MinEdge coordinates required, type was "..type(obj._minp))
obj._maxp = bounds.MaxEdge
assert(type(obj._maxp) == "table", "VoxelArea: MaxEdge coordinates required, type was "..type(obj._maxp))
setmetatable(obj, VoxelArea)
return obj
end

mineunit.export_object(VoxelArea, {
name = "VoxelArea",
constructor = function(self, minedge, maxedge)
error("Use VoxelArea:new to create new VoxelArea instance")
end,
})