Definition
A tuple of four integers (left, top, right, bottom) used in graphics libraries (like Pillow) to define a rectangular region.
Why It Matters
The “one-past-the-end” model of exclusive boundaries eliminates off-by-one errors and simplifies interval arithmetic for cropping and collision detection. This convention ensures that adjacent regions can be joined perfectly without overlapping the same pixel, providing the fundamental logic for clean graphics processing and UI design.
Core Concepts
- Boundary Rules:
- Left and Top: Inclusive.
- Right and Bottom: Exclusive.
- The “One-Past-the-End” Model: The
rightinteger is the x-coordinate of the first pixel to the right of the box; thebottominteger is the y-coordinate of the first pixel below the box. - Relationship to Slicing: This mirrors Python’s list slicing (
list[start:stop]), where thestopindex is not included in the result. - Example: A box tuple of
(3, 1, 9, 6)covers 6 pixels horizontally (9 minus 3) and 5 pixels vertically (6 minus 1).