diff options
author | FaceDeer <derksenmobile@gmail.com> | 2017-02-25 21:47:16 -0700 |
---|---|---|
committer | FaceDeer <derksenmobile@gmail.com> | 2017-02-25 21:47:16 -0700 |
commit | 486be59ebace5e0eaec8a7f2e9a5dbc82d4f1979 (patch) | |
tree | e3f0939ef9e914e3377aa33925d44e1e6d880162 | |
parent | cdc53e7757bd8718b4d3e321fd1508e53ab204b0 (diff) |
added a few features to this class while working on another mod
-rw-r--r-- | class_pointset.lua | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/class_pointset.lua b/class_pointset.lua index 5bfd22a..3cbbd89 100644 --- a/class_pointset.lua +++ b/class_pointset.lua @@ -1,5 +1,4 @@ --- A simple special-purpose class, this is used for building up sets of three-dimensional points --- I only added features to it as I needed them so may not be highly useful outside of this mod's context. +-- A simple special-purpose class, this is used for building up sets of three-dimensional points for fast reference Pointset = {} Pointset.__index = Pointset @@ -38,6 +37,18 @@ function Pointset:get(x, y, z) return self.points[x][y][z] end +function Pointset:set_pos(pos, value) + self:set(pos.x, pos.y, pos.z, value) +end + +function Pointset:set_pos_if_not_in(excluded, pos, value) + self:set_if_not_in(excluded, pos.x, pos.y, pos.z, value) +end + +function Pointset:get_pos(pos) + return self:get(pos.x, pos.y, pos.z) +end + function Pointset:pop() -- returns a point that's in the 3D array, and then removes it. local pos = {} @@ -70,4 +81,21 @@ function Pointset:pop() end return pos, val -end
\ No newline at end of file +end + +function Pointset:get_pos_list(value) + -- Returns a list of all points with the given value in standard Minetest vector format. If no value is provided, returns all points + local outlist = {} + for x, ytable in ipairs(self.points) do + for y, ztable in ipairs(ytable) do + for z, val in ipairs(ztable) do + if (value == nil and val ~= nil ) or val == value then + table.insert(outlist, {x=x, y=y, z=z}) + end + end + end + end + return outlist +end + +
\ No newline at end of file |