ShapedSelections can now return its positions as an iterator of tuples
Allows non-optimized algorithms to use `selection.positions`
This commit is contained in:
parent
f625d1f16b
commit
1a0a7fb938
@ -6,9 +6,9 @@ class Operation(object):
|
||||
A function that operates on every chunk within a selection. Can be composed with other operations.
|
||||
|
||||
:param selection: Area to operate within
|
||||
:type selection: SelectionBox
|
||||
:type selection: mceditlib.selection.SelectionBox
|
||||
:param dimension: World dimension to operate on
|
||||
:type dimension: WorldEditorDimension
|
||||
:type dimension: mceditlib.worldeditor.WorldEditorDimension
|
||||
"""
|
||||
self.dimension = dimension
|
||||
self.selection = selection
|
||||
|
@ -101,6 +101,14 @@ class SelectionBox(object):
|
||||
return self.box_mask(SectionBox(cx, cy, cz))
|
||||
|
||||
def box_mask(self, box):
|
||||
"""
|
||||
Return a boolean mask array for the given bounding box. Array indices are ordered YZX.
|
||||
|
||||
:param box:
|
||||
:type box:
|
||||
:return:
|
||||
:rtype: ndarray | None
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
mincx = NotImplemented
|
||||
@ -613,6 +621,18 @@ class ShapedSelection(BoundingBox):
|
||||
def __cmp__(self, b):
|
||||
return cmp((self.origin, self.size, self.shapeFunc), None if b is None else (b.origin, b.size, b.shapeFunc))
|
||||
|
||||
@property
|
||||
def positions(self):
|
||||
for cx, cz in self.chunkPositions():
|
||||
for cy in self.sectionPositions(cx, cz):
|
||||
mask = self.section_mask(cx, cy, cz)
|
||||
y, z, x = mask.nonzero()
|
||||
x = x + (cx << 4)
|
||||
y = y + (cy << 4)
|
||||
z = z + (cz << 4)
|
||||
for i in range(len(x)):
|
||||
yield x[i], y[i], z[i]
|
||||
|
||||
|
||||
# --- Shape functions ---
|
||||
|
||||
|
Reference in New Issue
Block a user