Skip to main content

Rect

Struct Rect 

Source
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: f64

Horizontal coordinate of the first corner.

§top: f64

Vertical coordinate of the first corner.

§right: f64

Horizontal coordinate of the opposite corner.

§bottom: f64

Vertical coordinate of the opposite corner.

Implementations§

Source§

impl Rect

Source

pub const fn new(left: f64, top: f64, right: f64, bottom: f64) -> Self

Preserves two corners without sorting, clamping or changing their meaning.

Source

pub fn from_origin_size(origin: Point, size: Size) -> Self

Creates bounds from a top-left position and signed dimensions.

Source

pub fn from_center_size(center: Point, size: Size) -> Self

Creates bounds around a center with signed dimensions.

Source

pub fn from_size(size: Size) -> Self

Creates bounds at the coordinate origin with these dimensions.

Source

pub fn width(self) -> f64

Returns the signed horizontal span; subtraction can overflow for extremes.

Source

pub fn height(self) -> f64

Returns the signed vertical span; subtraction can overflow for extremes.

Source

pub fn size(self) -> Size

Returns signed dimensions without normalization.

Source

pub fn center(self) -> Point

Returns the midpoint without adding two unscaled large coordinates.

Source

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.

Source

pub fn is_finite(self) -> bool

Whether all four stored coordinates are finite; spans may still overflow.

Source

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.

Source

pub fn contains(self, point: Point) -> bool

Tests a finite point with half-open edge ownership. Invalid bounds reject it.

Source

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.

Source

pub fn intersect(self, other: Self) -> Self

Returns overlapping bounds, clamping each disjoint span to zero at the greater origin. A nonfinite operand is propagated unchanged.

Source

pub fn inset(self, amount: f64) -> Self

Moves every edge inward by a signed amount; negative values expand. Excessive positive amounts preserve inverted, empty bounds.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rect

Source§

impl Debug for Rect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rect

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Rect> for RectClip

Source§

fn from(bounds: Rect) -> Self

Converts to this type from the input type.
Source§

impl Interpolate for Rect

Source§

fn interpolate(&self, target: &Self, progress: f64) -> Self

Blends toward target with nominal progress zero at self and one at target. Read more
Source§

impl PartialEq for Rect

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Shape for Rect

Source§

fn path(&self) -> Result<Path2D, ValidationError>

Returns a checked path snapshot without f32 narrowing.
Source§

fn bounding_box(&self) -> Result<Rect, ValidationError>

Geometric bounds; defaults to the path’s cached curve bounds.
Source§

fn as_rect(&self) -> Option<Rect>

Exact rectangle equivalent, when available, for a rule-independent fast path.
Source§

fn fill(self, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized,

Adds floating fill paint, using the nonzero rule by default.
Source§

fn stroke(self, width: f64, paint: impl Into<Paint>) -> Styled<Self>
where Self: Sized,

Adds a bounded curve/path stroke without an implicit fill.
Source§

impl StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Forget for Rect

§

impl Freeze for Rect

§

impl Move for Rect

§

impl RefUnwindSafe for Rect

§

impl Send for Rect

§

impl Sync for Rect

§

impl Unpin for Rect

§

impl UnsafeUnpin for Rect

§

impl UnwindSafe for Rect

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Geometry> IntoShapeClip for Geometry
where Geometry: Shape,

Source§

fn into_shape_clip(self) -> Result<ShapeClip, ValidationError>

Captures the clip geometry, reporting invalid shapes.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.