Module bbox¶
The bbox module defines axis-aligned bounding boxes (bbox,
bbox_pt, and empty) used throughout PyX to compute the spatial
extent of paths, text boxes, canvases, and pages. While you most commonly obtain
a bounding box by calling an object’s bbox() method (such as
canvas.canvas.bbox() or path.path.bbox()), you can also construct and
manipulate bounding boxes directly—for example, to pass a custom clipping or page
bounding box to canvas.canvas.writeEPSfile() or document.page.
Constructing Bounding Boxes¶
- class bbox.bbox(llx, lly, urx, ury)¶
Constructs a bounding box with lower-left corner
(llx, lly)and upper-right corner(urx, ury)specified in user units or PyX lengths.
- class bbox.bbox_pt(llx_pt, lly_pt, urx_pt, ury_pt)¶
Constructs a bounding box with coordinates
(llx_pt, lly_pt)and(urx_pt, ury_pt)specified directly in PostScript points. Allbbox()methods on PyX objects returnbbox_ptinstances.
- class bbox.empty¶
Constructs an empty bounding box (containing no points, with
llx_pt=None). An empty bounding box evaluates toFalsein a boolean context (bool(bbox.empty()) == False), whereas any non-empty bounding box evaluates toTrue.
Set Operations and Methods¶
Two bounding boxes b1 and b2 can be combined using arithmetic operators:
Union (
b1 + b2orb1 += b2): Returns the smallest bounding box enclosing bothb1andb2. Adding anemptybounding box leaves the other bounding box unchanged.Intersection (
b1 * b2orb1 *= b2): Returns the overlapping region ofb1andb2(or anemptybounding box if either input is empty).
In addition, bbox and bbox_pt provide the following methods
(where measurement methods without a _pt suffix return true PyX lengths
unit.t_pt, and _pt variants take or return plain floats in PostScript
points):
Method |
Description |
|---|---|
|
Returns a copy of the bounding box. |
|
Copies the coordinates of other into |
|
Returns |
|
Expands |
|
Transforms the four corners of |
|
Returns a new bounding box enclosing |
|
Expands |
|
Returns a new bounding box expanded on each side by the
specified amounts (using all for any side left as
|
|
Returns a rectangular |
|
Returns the horizontal width of the bounding box. |
|
Returns the vertical height of the bounding box. |
|
Returns the x-coordinate of the left edge ( |
|
Returns the x-coordinate of the right edge ( |
|
Returns the y-coordinate of the bottom edge ( |
|
Returns the y-coordinate of the top edge ( |
|
Returns the |
|
Returns |
|
Returns |