pub struct Rect { /* private fields */ }Expand description
A rectangle defined by left, top, right and bottom edges.
Can have zero width and/or height. But not a negative one.
§Guarantees
- All values are finite.
- Left edge is <= right.
- Top edge is <= bottom.
- Width and height are <= f32::MAX.
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn from_ltrb(left: f32, top: f32, right: f32, bottom: f32) -> Option<Self>
pub fn from_ltrb(left: f32, top: f32, right: f32, bottom: f32) -> Option<Self>
Creates new Rect.
Sourcepub fn round(&self) -> Option<IntRect>
pub fn round(&self) -> Option<IntRect>
Converts into an IntRect by adding 0.5 and discarding the fractional portion.
Width and height are guarantee to be >= 1.
Sourcepub fn round_out(&self) -> Option<IntRect>
pub fn round_out(&self) -> Option<IntRect>
Converts into an IntRect rounding outwards.
Width and height are guarantee to be >= 1.
Sourcepub fn intersect(&self, other: &Self) -> Option<Self>
pub fn intersect(&self, other: &Self) -> Option<Self>
Returns an intersection of two rectangles.
Returns None otherwise.
Sourcepub fn join(&self, other: &Self) -> Option<Self>
pub fn join(&self, other: &Self) -> Option<Self>
Returns the union of two rectangles.
Returns None if the width or height would overflow.
Sourcepub fn from_points(points: &[Point]) -> Option<Self>
pub fn from_points(points: &[Point]) -> Option<Self>
Creates a Rect from Point array.
Returns None if count is zero or if Point array contains an infinity or NaN.
Sourcepub fn inset(&self, dx: f32, dy: f32) -> Option<Self>
pub fn inset(&self, dx: f32, dy: f32) -> Option<Self>
Insets the rectangle by the specified offset.
Sourcepub fn outset(&self, dx: f32, dy: f32) -> Option<Self>
pub fn outset(&self, dx: f32, dy: f32) -> Option<Self>
Outsets the rectangle by the specified offset.
Sourcepub fn transform(&self, ts: Transform) -> Option<Self>
pub fn transform(&self, ts: Transform) -> Option<Self>
Transforms the rect using the provided Transform.
If the transform is a skew, the result will be a bounding box around the skewed rectangle.
Sourcepub fn bbox_transform(&self, bbox: NonZeroRect) -> Self
pub fn bbox_transform(&self, bbox: NonZeroRect) -> Self
Applies a bounding box transform.
Sourcepub fn to_non_zero_rect(&self) -> Option<NonZeroRect>
pub fn to_non_zero_rect(&self) -> Option<NonZeroRect>
Converts into NonZeroRect.