amulet.api.selection.box
module¶
- class amulet.api.selection.SelectionBox(point_1, point_2)[source]¶
Bases:
AbstractBaseSelection
The SelectionBox class represents a single cuboid selection.
When combined with
SelectionGroup
it can represent any arbitrary shape.- __init__(point_1, point_2)[source]¶
Construct a new SelectionBox instance.
>>> # a selection box that selects one block. >>> box = SelectionBox( >>> (0, 0, 0), >>> (1, 1, 1) >>> )
- classmethod create_chunk_box(cx, cz, sub_chunk_size=16)[source]¶
Get a
SelectionBox
containing the whole of a given chunk.>>> box = SelectionBox.create_chunk_box(1, 2) SelectionBox((16, -1073741824, 32), (32, 1073741824, 48))
- Parameters
- Return type
- classmethod create_sub_chunk_box(cx, cy, cz, sub_chunk_size=16)[source]¶
Get a
SelectionBox
containing the whole of a given sub-chunk.>>> SelectionBox.create_sub_chunk_box(1, 0, 2) SelectionBox((16, 0, 32), (32, 16, 48))
- Parameters
- Return type
- create_moved_box(offset, subtract=False)[source]¶
Create a new
SelectionBox
based on this one with the coordinates moved by the given offset.
- 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(): >>> ...
- chunk_y_locations(sub_chunk_size=16)[source]¶
An iterable of all the sub-chunk y indexes this box intersects.
- 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(): >>> ...
- property blocks: Iterable[Tuple[int, int, int]][source]¶
The location of every block in the selection.
- Returns
An iterable of block locations.
- 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 slice: Tuple[slice, slice, slice][source]¶
Converts the
SelectionBox
minimum/maximum coordinates into slice arguments- Returns
The
SelectionBox
coordinates as slices in (x,y,z) order
- chunk_slice(cx, cz, sub_chunk_size=16)[source]¶
Get the slice of the box in relative form for a given chunk.
>>> SelectionBox((0, 0, 0), (32, 32, 32)).chunk_slice(1, 1) (slice(0, 16, None), slice(0, 32, None), slice(0, 16, None))
- sub_chunk_slice(cx, cy, cz, sub_chunk_size=16)[source]¶
Get the slice of the box in relative form for a given sub-chunk.
>>> SelectionBox((0, 0, 0), (32, 32, 32)).sub_chunk_slice(1, 1, 1) (slice(0, 16, None), slice(0, 16, None), slice(0, 16, None))
- property points: Tuple[Tuple[int, int, int], Tuple[int, int, int]][source]¶
The points given to the constructor.
- 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.
- property shape: Tuple[int, int, int][source]¶
The shape of the box.
>>> SelectionBox((0, 0, 0), (1, 1, 1)).shape (1, 1, 1)
- property volume: int[source]¶
The number of blocks in the box.
>>> SelectionBox((0, 0, 0), (1, 1, 1)).shape 1
- touches(other)[source]¶
Method to check if this instance of
SelectionBox
touches but does not intersect another SelectionBox.- Parameters
other (
SelectionBox
) – The other SelectionBox- Return type
- Returns
True if the two
SelectionBox
instances touch, False otherwise
- touches_or_intersects(other)[source]¶
Method to check if this instance of SelectionBox touches or intersects another SelectionBox.
- Parameters
other (
SelectionBox
) – The other SelectionBox.- Return type
- Returns
True if the two
SelectionBox
instances touch or intersect, False otherwise.
- intersects(other)[source]¶
Method to check whether this instance of SelectionBox intersects another SelectionBox.
- Parameters
other (
SelectionBox
) – The other SelectionBox to check for intersection.- Return type
- Returns
True if the two
SelectionBox
instances intersect, False otherwise.
- contains_box(other)[source]¶
Method to check if the other SelectionBox other fits entirely within this instance of SelectionBox.
- Parameters
other (
SelectionBox
) – The SelectionBox to test.- Return type
- Returns
True if other fits with self, 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 (
SelectionBox
) – The other selection.- Return type
- Returns
A new selection containing the intersection.
- subtract(other)[source]¶
Get a
SelectionGroup
containing boxes that are in self but not in other.This may be empty if other fully contains self or equal to self if they do not intersect.
- Parameters
other (
SelectionBox
) – The SelectionBox to subtract.- Return type
- Returns
- intersects_vector(origin, vector)[source]¶
Determine if a vector from a given point collides with this selection box.
- transformed_points(transform)[source]¶
Get the locations of the transformed blocks and the source blocks they came from.
- Parameters
transform (
ndarray
) – The matrix that this box will be transformed by.- Return type
Iterable
[Tuple
[float
,Optional
[ndarray
],Optional
[ndarray
]]]- Returns
An iterable of two Nx3 numpy arrays of the source block locations and the destination block locations. The destination locations will be unique but the source may not be and some may not be included.
- transform(scale, rotation, translation)[source]¶
Creates a
SelectionGroup
of transformed SelectionBox(es).- Parameters
- Return type
- Returns
A new
SelectionGroup
representing the transformed selection.