aboutsummaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authorAFCMS <afcm.contact@gmail.com>2022-07-09 22:32:33 +0200
committerGitHub <noreply@github.com>2022-07-09 22:32:33 +0200
commitfae8726a769f9ad3bb81bf3e364265662d333dd0 (patch)
treea94dd9f728aefec5664a3d779f769bfe5b4a836c /builtin/game
parente51f474613c5d4bd53a8d213785bcb51f5cf447f (diff)
downloadminetest-fae8726a769f9ad3bb81bf3e364265662d333dd0.tar.gz
minetest-fae8726a769f9ad3bb81bf3e364265662d333dd0.tar.bz2
minetest-fae8726a769f9ad3bb81bf3e364265662d333dd0.zip
Make `VoxelArea:position()` return a vector with metatable (#12521)
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/voxelarea.lua22
1 files changed, 12 insertions, 10 deletions
diff --git a/builtin/game/voxelarea.lua b/builtin/game/voxelarea.lua
index 64436bf1a..62f07d928 100644
--- a/builtin/game/voxelarea.lua
+++ b/builtin/game/voxelarea.lua
@@ -1,6 +1,9 @@
+local math_floor = math.floor
+local vector_new = vector.new
+
VoxelArea = {
- MinEdge = vector.new(1, 1, 1),
- MaxEdge = vector.new(0, 0, 0),
+ MinEdge = vector_new(1, 1, 1),
+ MaxEdge = vector_new(0, 0, 0),
ystride = 0,
zstride = 0,
}
@@ -19,7 +22,7 @@ end
function VoxelArea:getExtent()
local MaxEdge, MinEdge = self.MaxEdge, self.MinEdge
- return vector.new(
+ return vector_new(
MaxEdge.x - MinEdge.x + 1,
MaxEdge.y - MinEdge.y + 1,
MaxEdge.z - MinEdge.z + 1
@@ -36,7 +39,7 @@ function VoxelArea:index(x, y, z)
local i = (z - MinEdge.z) * self.zstride +
(y - MinEdge.y) * self.ystride +
(x - MinEdge.x) + 1
- return math.floor(i)
+ return math_floor(i)
end
function VoxelArea:indexp(p)
@@ -44,24 +47,23 @@ function VoxelArea:indexp(p)
local i = (p.z - MinEdge.z) * self.zstride +
(p.y - MinEdge.y) * self.ystride +
(p.x - MinEdge.x) + 1
- return math.floor(i)
+ return math_floor(i)
end
function VoxelArea:position(i)
- local p = {}
local MinEdge = self.MinEdge
i = i - 1
- p.z = math.floor(i / self.zstride) + MinEdge.z
+ local z = math_floor(i / self.zstride) + MinEdge.z
i = i % self.zstride
- p.y = math.floor(i / self.ystride) + MinEdge.y
+ local y = math_floor(i / self.ystride) + MinEdge.y
i = i % self.ystride
- p.x = math.floor(i) + MinEdge.x
+ local x = math_floor(i) + MinEdge.x
- return p
+ return vector_new(x, y, z)
end
function VoxelArea:contains(x, y, z)