@@ -44,6 +44,22 @@ function VoxelArea:indexp(p)
44
44
return math.floor (i )
45
45
end
46
46
47
+ function VoxelArea :position (i )
48
+ local p = {}
49
+
50
+ i = i - 1
51
+
52
+ p .z = math.floor (i / self .zstride ) + self .MinEdge .z
53
+ i = i % self .zstride
54
+
55
+ p .y = math.floor (i / self .ystride ) + self .MinEdge .y
56
+ i = i % self .ystride
57
+
58
+ p .x = math.floor (i ) + self .MinEdge .x
59
+
60
+ return p
61
+ end
62
+
47
63
function VoxelArea :contains (x , y , z )
48
64
return (x >= self .MinEdge .x ) and (x <= self .MaxEdge .x ) and
49
65
(y >= self .MinEdge .y ) and (y <= self .MaxEdge .y ) and
@@ -60,3 +76,28 @@ function VoxelArea:containsi(i)
60
76
return (i >= 1 ) and (i <= self :getVolume ())
61
77
end
62
78
79
+ function VoxelArea :iter (minx , miny , minz , maxx , maxy , maxz )
80
+ local i = self :index (minx , miny , minz ) - 1
81
+ local last = self :index (maxx , maxy , maxz )
82
+ local ystride = self .ystride
83
+ local zstride = self .zstride
84
+ local yoff = (last + 1 ) % ystride
85
+ local zoff = (last + 1 ) % zstride
86
+ local ystridediff = (i - last ) % ystride
87
+ local zstridediff = (i - last ) % zstride
88
+ return function ()
89
+ i = i + 1
90
+ if i % zstride == zoff then
91
+ i = i + zstridediff
92
+ elseif i % ystride == yoff then
93
+ i = i + ystridediff
94
+ end
95
+ if i <= last then
96
+ return i
97
+ end
98
+ end
99
+ end
100
+
101
+ function VoxelArea :iterp (minp , maxp )
102
+ return self :iter (minp .x , minp .y , minp .z , maxp .x , maxp .y , maxp .z )
103
+ end
0 commit comments