Bounds

Axis-aligned bounding boxes for 2-D and 3-D geometry

Axis-aligned bounding boxes for 2-D and 3-D geometry.

Bounds2D and Bounds3D are what every bounds() in pybosl2 returns (SPEC S-2b) – shapes on either backend, Path2D, Path3D, Region and VNF. One name, one meaning: bounds() answers a box, and the box carries every spelling of itself so no caller has to do the arithmetic and no implementation has to pick a winner:

box = cuboid([40, 30, 20]).bounds()
box.min, box.max        # corners, as Points
box.center, box.size    # centre and extent
box.width               # or .length / .height

They used to disagree – shapes answered a bare (centre, size) pair, paths and meshes a dataclass, regions a NumPy array – so lo, hi = solid.bounds(), the obvious reading of the name, silently bound a centre to lo. These types are the single answer.

class pybosl2.bounds.Bounds2D(min_x, min_y, max_x, max_y, width, length)[source]

Bases: object

Axis-aligned bounding box of a 2-D path.

Returned by bounds() with the min/max corners and pre-computed width and length.

Parameters:
min_x : float

min_y : float

max_x : float

max_y : float

width : float

length : float

min_x : float
min_y : float
max_x : float
max_y : float
width : float
length : float
property center : Point

The (x, y) centre of the bounding box as a 2‑D Point.

property size : tuple[float, float]

The (width, length) of the bounding box.

property min : Point

The lower corner as a 2-D Point.

property max : Point

The upper corner as a 2-D Point.

classmethod from_min_max(lo, hi)[source]

Build from the two opposite corners.

Parameters:
lo : Sequence[float]

the lower corner, [x, y].

hi : Sequence[float]

the upper corner, [x, y].

Returns:

The bounding box, with width and length derived.

Return type:

Bounds2D

Examples

>>> Bounds2D.from_min_max([0, 0], [10, 5]).size
(10.0, 5.0)
classmethod from_center_size(center, size)[source]

Build from a centre point and an extent.

This is the form the native backends report, so it is the conversion every shape’s bounds() goes through rather than doing the halving inline.

Parameters:
center : Sequence[float]

the box centre, [x, y].

size : Sequence[float]

the box extent, [width, length].

Returns:

The bounding box, with the corners derived.

Return type:

Bounds2D

Examples

>>> Bounds2D.from_center_size([0, 0], [10, 5]).min_x
-5.0
class pybosl2.bounds.Bounds3D(min_x, min_y, min_z, max_x, max_y, max_z, width, length, height)[source]

Bases: object

Axis-aligned bounding box of a 3-D path or solid.

Returned by bounds() and solid bounding-box methods with the min/max corners and pre-computed width, length, and height.

Parameters:
min_x : float

min_y : float

min_z : float

max_x : float

max_y : float

max_z : float

width : float

length : float

height : float

min_x : float
min_y : float
min_z : float
max_x : float
max_y : float
max_z : float
width : float
length : float
height : float
property center : Point

The (x, y, z) centre of the bounding box as a 3‑D Point.

property size : tuple[float, float, float]

The (width, length, height) of the bounding box.

property min : Point

The lower corner as a 3-D Point.

property max : Point

The upper corner as a 3-D Point.

classmethod from_min_max(lo, hi)[source]

Build from the two opposite corners.

Parameters:
lo : Sequence[float]

the lower corner, [x, y, z].

hi : Sequence[float]

the upper corner, [x, y, z].

Returns:

The bounding box, with width, length and height derived.

Return type:

Bounds3D

Examples

>>> Bounds3D.from_min_max([0, 0, 0], [10, 5, 2]).size
(10.0, 5.0, 2.0)
classmethod from_center_size(center, size)[source]

Build from a centre point and an extent.

This is the form the native backends report, so it is the conversion every solid’s bounds() goes through rather than doing the halving inline.

Parameters:
center : Sequence[float]

the box centre, [x, y, z].

size : Sequence[float]

the box extent, [width, length, height].

Returns:

The bounding box, with the corners derived.

Return type:

Bounds3D

Examples

>>> Bounds3D.from_center_size([0, 0, 0], [40, 30, 20]).min_z
-10.0