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 VoxelArea() constructor #12886

Merged
merged 1 commit into from
Oct 22, 2022
Merged
Show file tree
Hide file tree
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
Add VoxelArea() constructor
  • Loading branch information
TurkeyMcMac committed Oct 20, 2022
commit 89d7b70ac47594b5041a3561028d7880e18b7259
11 changes: 10 additions & 1 deletion builtin/game/voxelarea.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ VoxelArea = {
zstride = 0,
}

function VoxelArea:new(o)
local class_metatable = {}
setmetatable(VoxelArea, class_metatable)

local function new(self, o)
o = o or {}
setmetatable(o, self)
self.__index = self
Expand All @@ -20,6 +23,12 @@ function VoxelArea:new(o)
return o
end

function class_metatable:__call(MinEdge, MaxEdge)
return new(self, {MinEdge = MinEdge, MaxEdge = MaxEdge})
end

VoxelArea.new = new

function VoxelArea:getExtent()
local MaxEdge, MinEdge = self.MaxEdge, self.MinEdge
return vector_new(
Expand Down
5 changes: 3 additions & 2 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4485,7 +4485,8 @@ Methods
-----------

A helper class for voxel areas.
It can be created via `VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
It can be created via `VoxelArea(pmin, pmax)` or
`VoxelArea:new({MinEdge = pmin, MaxEdge = pmax})`.
The coordinates are *inclusive*, like most other things in Minetest.

### Methods
Expand Down Expand Up @@ -4533,7 +4534,7 @@ the axes in a voxel area:

If, for example:

local area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
local area = VoxelArea(emin, emax)

The values of `ystride` and `zstride` can be obtained using `area.ystride` and
`area.zstride`.
Expand Down