pub struct RectU16 {
pub x0: u16,
pub y0: u16,
pub x1: u16,
pub y1: u16,
}Expand description
An axis-aligned rectangle with u16 coordinates, stored as two corners (x0, y0) and
(x1, y1).
(x0, y0) is the top-left (minimum) corner and (x1, y1) is the bottom-right (maximum) corner.
The rectangle is considered to be empty when x0 >= x1 or y0 >= y1.
Fields§
§x0: u16The minimum x coordinate (left edge).
y0: u16The minimum y coordinate (top edge).
x1: u16The maximum x coordinate (right edge, exclusive).
y1: u16The maximum y coordinate (bottom edge, exclusive).
Implementations§
Source§impl RectU16
impl RectU16
Sourcepub const INVERTED: Self
pub const INVERTED: Self
An empty, maximally inverted rectangle, useful as a starting value for incremental union operations.
Has (x0, y0) = (u16::MAX, u16::MAX) and (x1, y1) = (0, 0).
Sourcepub const fn new(x0: u16, y0: u16, x1: u16, y1: u16) -> Self
pub const fn new(x0: u16, y0: u16, x1: u16, y1: u16) -> Self
Create a new rectangle from its corner coordinates.
Sourcepub const fn is_empty(self) -> bool
pub const fn is_empty(self) -> bool
Returns true if the rectangle has zero area (x0 >= x1 or y0 >= y1).
Sourcepub const fn contains(self, x: u16, y: u16) -> bool
pub const fn contains(self, x: u16, y: u16) -> bool
Check if a point (x, y) is contained within this rectangle.
Returns true if x0 <= x < x1 and y0 <= y < y1.
Sourcepub const fn intersect(self, other: Self) -> Self
pub const fn intersect(self, other: Self) -> Self
Compute the intersection of two rectangles.
The result may have zero area if the rectangles do not overlap, but is never inverted.
Sourcepub const fn expand(self, padding: PaddingU16) -> Self
pub const fn expand(self, padding: PaddingU16) -> Self
Expand this rectangle by the given left, top, right, and bottom padding.
Sourcepub fn relative_to_origin(self, origin: (u16, u16)) -> Self
pub fn relative_to_origin(self, origin: (u16, u16)) -> Self
Return this rectangle relative to origin, clamping negative coordinates to zero.
Sourcepub fn shift(self, shift: (i32, i32)) -> Self
pub fn shift(self, shift: (i32, i32)) -> Self
Return a shifted version of the rectangle, clamping negative coordinates to zero.
Sourcepub const fn union(&mut self, other: Self)
pub const fn union(&mut self, other: Self)
Expand this rectangle to also cover other (union in place).
The union of self with a Self::INVERTED returns self.