Rect
An axis-aligned rectangle: its top-left corner and its size. Width and height are expected to be non-negative.
Import
Section titled “Import”Cargo feature geometry (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”The right edge, x + width.
Returns
f64 — The x coordinate of the right edge.
Examples
The smallest rectangle that contains both self and other.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | &Self | The other rectangle. |
Returns
Self — The bounding rectangle.
Examples
bounding
Section titled “bounding”The smallest rectangle that contains all of rects, e.g. the bounds of a group of layers.
Parameters
| Parameter | Type | Description |
|---|---|---|
rects | &[Self] | The rectangles. |
Returns
Option<Self> — The bounding rectangle, or None for no rectangle.
Examples
intersection
Section titled “intersection”The area self and other have in common.
Rectangles that only touch (along an edge or at a corner) have no area in common.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | &Self | The other rectangle. |
Returns
Option<Self> — The overlapping rectangle, or None when they do not overlap.
Examples
intersects
Section titled “intersects”Whether self and other have an area in common: exactly when
intersection returns a rectangle (touching rectangles and empty
ones do not).
Parameters
| Parameter | Type | Description |
|---|---|---|
other | &Self | The other rectangle. |
Returns
bool — true if they overlap.
Examples
contains_point
Section titled “contains_point”Whether a point is inside the rectangle, for hit-testing.
The left and top edges are inside, the right and bottom ones are not, so a point on the edge between two adjacent rectangles hits exactly one of them.
Parameters
| Parameter | Type | Description |
|---|---|---|
point | Point | The point to test. |
Returns
bool — true if the point is inside.
Examples
contains_rect
Section titled “contains_rect”Whether other is inside the rectangle: it does not stick out on any side, and may touch
any edge.
Parameters
| Parameter | Type | Description |
|---|---|---|
other | &Self | The rectangle to test. |
Returns
bool — true if other is entirely inside (or equal to) self.
Examples
bottom
Section titled “bottom”The bottom edge, y + height.
Returns
f64 — The y coordinate of the bottom edge.
Examples
