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:
objectAxis-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¶
- property size : tuple[float, float]¶
The (width, length) of the bounding box.
- classmethod from_min_max(lo, hi)[source]¶
Build from the two opposite corners.
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.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:
objectAxis-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¶
- property size : tuple[float, float, float]¶
The (width, length, height) of the bounding box.
- classmethod from_min_max(lo, hi)[source]¶
Build from the two opposite corners.
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.Examples
>>> Bounds3D.from_center_size([0, 0, 0], [40, 30, 20]).min_z -10.0