amulet.api.selection.group
module¶
- class amulet.api.selection.SelectionGroup(selection_boxes=())[source]¶
Bases:
AbstractBaseSelection
A container for zero or more
SelectionBox
instances.This allows for non-rectangular and non-contiguous selections.
- __init__(selection_boxes=())[source]¶
Construct a new
SelectionGroup
class from the given data.>>> SelectionGroup(SelectionBox((0, 0, 0), (1, 1, 1))) >>> SelectionGroup([ >>> SelectionBox((0, 0, 0), (1, 1, 1)), >>> SelectionBox((1, 1, 1), (2, 2, 2)) >>> ])
- Parameters
selection_boxes (
Union
[SelectionBox
,Iterable
[SelectionBox
]]) – ASelectionBox
or iterable ofSelectionBox
classes.
- contains_block(coords)[source]¶
Is the block contained within the selection.
>>> (1, 2, 3) in selection1 True
- contains_point(coords)[source]¶
Is the point contained within the selection.
>>> (1.5, 2.5, 3.5) in selection1 True
- property blocks: Iterable[Tuple[int, int, int]][source]¶
The location of every block in the selection.
>>> for x, y, z in group.blocks: >>> ...
Note: if boxes intersect, the blocks in the intersected region will be included multiple times.
If this behaviour is not desired the
merge_boxes()
method will return a new SelectionGroup with no intersections.>>> for x, y, z in group.merge_boxes().blocks: >>> ...
- Returns
An iterable of block locations.
- property min_array: ndarray[source]¶
The minimum point of of all the boxes in the group as a numpy array.
- property max_array: ndarray[source]¶
The maximum point of of all the boxes in the group as a numpy array.
- property bounds: Tuple[Tuple[int, int, int], Tuple[int, int, int]][source]¶
The minimum and maximum points in the selection.
- property bounds_array: ndarray[source]¶
The minimum and maximum points in the selection as a numpy array.
- merge_boxes()[source]¶
Take the boxes as they were given to this class, merge neighbouring boxes and remove overlapping regions.
The result should be a SelectionGroup containing one or more SelectionBox classes that represents the same volume as the original but with no overlapping boxes.
- Return type
- property is_contiguous: bool[source]¶
Does the SelectionGroup represent one connected region (True) or multiple separated regions (False).
If two boxes are touching at the corners this is classed as contiguous.
- property is_rectangular: bool[source]¶
Checks if the SelectionGroup is a rectangle
- Returns
True is the selection is a rectangle, False otherwise
- property selection_boxes: Tuple[SelectionBox, ...][source]¶
A tuple of the
SelectionBox
instances stored for this group.
- property selection_boxes_sorted: List[SelectionBox][source]¶
A list of the
SelectionBox
instances for this group sorted by their hash.
- chunk_locations(sub_chunk_size=16)[source]¶
An iterable of chunk coordinates that intersect the selection.
>>> for cx, cz in selection1.chunk_locations(): >>> ...
- chunk_boxes(sub_chunk_size=16)[source]¶
An iterable of chunk coordinates and boxes that intersect the selection and the chunk.
>>> for (cx, cz), box in selection1.chunk_boxes(): >>> ...
- sub_chunk_locations(sub_chunk_size=16)[source]¶
An iterable of sub-chunk coordinates that intersect the selection.
>>> for cx, cy, cz in selection1.sub_chunk_locations(): >>> ...
- sub_chunk_boxes(sub_chunk_size=16)[source]¶
An iterable of sub-chunk coordinates and boxes that intersect the selection and the sub-chunk.
>>> for (cx, cy, cz), box in selection1.sub_chunk_boxes(): >>> ...
- intersects(other)[source]¶
Does this selection intersect
other
.- Parameters
other (
Union
[SelectionGroup
,SelectionBox
]) – The other selection.- Return type
- Returns
True if the selections intersect, False otherwise.
- intersection(other)[source]¶
Create and return a new a selection containing the volume that this selection and other both contain.
If the selections do not intersect the returned selection will have no volume.
Use
intersects()
to test if the two selections intersect.- Parameters
other (
Union
[SelectionGroup
,SelectionBox
]) – The other selection.- Return type
- Returns
A new selection containing the intersection.
- subtract(other)[source]¶
Returns a new
SelectionGroup
containing the volume that does not intersect with other.This may be empty if other fully contains self or equal to self if they do not intersect.
- Parameters
other (
Union
[SelectionGroup
,SelectionBox
]) – TheSelectionBox
orSelectionGroup
to subtract.- Return type
- union(other)[source]¶
Returns a new SelectionGroup containing the volume of self and other.
- Parameters
other (
Union
[SelectionGroup
,SelectionBox
]) – The other selection to add to this one.- Return type
- is_subset(other)[source]¶
Is this selection completely contained within
other
.- Parameters
other (
Union
[SelectionGroup
,SelectionBox
]) – The other selection to test against.- Return type
- Returns
True if this selection completely fits in other.
- closest_vector_intersection(origin, vector)[source]¶
Returns the index for the closest box in the look vector and the multiplier of the look vector to get there.
- Parameters
- Return type
- Returns
Index for the closest box and the multiplier of the vector to get there. None, inf if no intersection.
- transform(scale, rotation, translation)[source]¶
Creates a new
SelectionGroup
transformed by the given inputs.- Parameters
- Return type
- Returns
A new
SelectionGroup
representing the transformed selection.