pub struct Rect<T = u32> {
pub left: Option<T>,
pub top: Option<T>,
pub right: Option<T>,
pub bottom: Option<T>,
}Expand description
An axis-aligned rectangular region.
Each of the four sides of a Rect can be either bounded (Some(_)) or
unbounded (None). If bounded, the start bounds (left and top) are always
inclusive, and the end bounds (right and bottom) are always exclusive.
If left and right are unbounded and right ≤ left, the Rect is
considered empty. The same holds for top and bottom. This matches the
semantics of the standard Range type.
Fields§
§left: Option<T>The left bound of self, if any.
top: Option<T>The top bound of self, if any.
right: Option<T>The right bound of self, if any.
bottom: Option<T>The bottom bound of self, if any.
Implementations§
Source§impl<T: Copy> Rect<T>
impl<T: Copy> Rect<T>
Sourcepub fn width(&self) -> Option<T::Output>
pub fn width(&self) -> Option<T::Output>
Returns the width of self, or None if horizontally unbounded.
Returns 0 if right <= left.
Sourcepub fn height(&self) -> Option<T::Output>
pub fn height(&self) -> Option<T::Output>
Returns the height of self, or None if vertically unbounded.
Returns 0 if bottom <= top.
Sourcepub fn is_empty(&self) -> boolwhere
T: PartialOrd,
pub fn is_empty(&self) -> boolwhere
T: PartialOrd,
Returns whether self contains no points.
Sourcepub fn contains(&self, x: T, y: T) -> boolwhere
T: PartialOrd,
pub fn contains(&self, x: T, y: T) -> boolwhere
T: PartialOrd,
Returns whether the point (x, y) is contained within self.
Sourcepub fn bounds(&self) -> [impl RangeBounds<T>; 2]
pub fn bounds(&self) -> [impl RangeBounds<T>; 2]
Returns the horizontal and vertical extents of self.
Sourcepub fn intersect(&self, other: &Self) -> Selfwhere
T: Ord,
pub fn intersect(&self, other: &Self) -> Selfwhere
T: Ord,
Returns the intersection of self and other.
The intersection is a rect that contains exactly the points contained
by both self and other. If the input rects are disjoint, i.e.
contain no common points, the result is an empty rect with unspecified
top-left coordinates.