pub struct Rect {
pub left: f64,
pub top: f64,
pub right: f64,
pub bottom: f64,
}Expand description
Double-precision bounds specified by opposite corners, not width and height.
Coordinates are preserved, not sorted or clamped. Inverted or zero-area bounds are empty. Positive inset shrinks; excessive inset produces inverted bounds. Containment is half-open: left/top are included and right/bottom are excluded.
use motion_core::prelude::*;
use motion_core::{
DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let bounds = Rect::new(10.0, 20.0, 40.0, 30.0);
assert_eq!(bounds.size(), Size::new(30.0, 10.0));
assert_eq!(bounds.center(), Point::new(25.0, 25.0));
assert!(bounds.contains(Point::new(10.0, 20.0)));
assert!(!bounds.contains(Point::new(40.0, 30.0)));Fields§
§left: f64Horizontal coordinate of the first corner.
top: f64Vertical coordinate of the first corner.
right: f64Horizontal coordinate of the opposite corner.
bottom: f64Vertical coordinate of the opposite corner.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(left: f64, top: f64, right: f64, bottom: f64) -> Self
pub const fn new(left: f64, top: f64, right: f64, bottom: f64) -> Self
Preserves two corners without sorting, clamping or changing their meaning.
Sourcepub fn from_origin_size(origin: Point, size: Size) -> Self
pub fn from_origin_size(origin: Point, size: Size) -> Self
Creates bounds from a top-left position and signed dimensions.
Sourcepub fn from_center_size(center: Point, size: Size) -> Self
pub fn from_center_size(center: Point, size: Size) -> Self
Creates bounds around a center with signed dimensions.
Sourcepub fn from_size(size: Size) -> Self
pub fn from_size(size: Size) -> Self
Creates bounds at the coordinate origin with these dimensions.
Sourcepub fn width(self) -> f64
pub fn width(self) -> f64
Returns the signed horizontal span; subtraction can overflow for extremes.
Sourcepub fn height(self) -> f64
pub fn height(self) -> f64
Returns the signed vertical span; subtraction can overflow for extremes.
Sourcepub fn center(self) -> Point
pub fn center(self) -> Point
Returns the midpoint without adding two unscaled large coordinates.
Sourcepub fn anchor(self, pivot: Pivot) -> Point
pub fn anchor(self, pivot: Pivot) -> Point
Resolves an anchor without normalizing or clamping the stored bounds.
Baseline uses the non-text BottomLeft fallback. Relative coordinates can extrapolate; invalid or unrepresentable arithmetic remains observable.
Sourcepub fn is_finite(self) -> bool
pub fn is_finite(self) -> bool
Whether all four stored coordinates are finite; spans may still overflow.
Sourcepub fn is_empty(self) -> bool
pub fn is_empty(self) -> bool
Whether a finite rectangle has no positive area, including inverted bounds. Nonfinite coordinates are invalid, not a usable empty rectangle.
Sourcepub fn contains(self, point: Point) -> bool
pub fn contains(self, point: Point) -> bool
Tests a finite point with half-open edge ownership. Invalid bounds reject it.
Sourcepub fn union(self, other: Self) -> Self
pub fn union(self, other: Self) -> Self
Returns enclosing bounds, ignoring empty operands. If both are empty, returns the second operand. A nonfinite operand is propagated unchanged.
Trait Implementations§
impl Copy for Rect
Source§impl Interpolate for Rect
impl Interpolate for Rect
Source§fn interpolate(&self, target: &Self, progress: f64) -> Self
fn interpolate(&self, target: &Self, progress: f64) -> Self
target with nominal progress zero at self and one at target. Read more