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

An immutable, 2D, axis-aligned, floating-point rectangle whose coordinates are relative to a given origin.

A Rect can be created with one of its constructors or from an Offset and a Size using the & operator:

let my_rect = Offset::new(1.0, 2.0) & Size::new(3.0, 4.0);

Fields§

§left: f64

The offset of the left edge of this rectangle from the x axis.

§top: f64

The offset of the top edge of this rectangle from the y axis.

§right: f64

The offset of the right edge of this rectangle from the x axis.

§bottom: f64

The offset of the bottom edge of this rectangle from the y axis.

Implementations§

Source§

impl Rect

Source

pub const ZERO: Rect

A rectangle with left, top, right, and bottom edges all at zero.

Source

pub const LARGEST: Rect

A rectangle that covers the entire coordinate space.

This covers the space from -1e9,-1e9 to 1e9,1e9. This is the space over which graphics operations are valid.

Source

pub const fn from_ltrb(left: f64, top: f64, right: f64, bottom: f64) -> Rect

Construct a rectangle from its left, top, right, and bottom edges.

Source

pub const fn from_ltwh(left: f64, top: f64, width: f64, height: f64) -> Rect

Construct a rectangle from its left and top edges, its width, and its height.

To construct a Rect from an Offset and a Size, you can use the rectangle constructor operator &. See BitAnd for Offset.

Source

pub fn from_circle(center: Offset, radius: f64) -> Rect

Construct a rectangle that bounds the given circle.

The center argument is assumed to be an offset from the origin.

Source

pub fn from_center(center: Offset, width: f64, height: f64) -> Rect

Constructs a rectangle from its center point, width, and height.

The center argument is assumed to be an offset from the origin.

Source

pub fn from_points(a: Offset, b: Offset) -> Rect

Construct the smallest rectangle that encloses the given offsets, treating them as vectors from the origin.

Source

pub fn width(&self) -> f64

The distance between the left and right edges of this rectangle.

Source

pub fn height(&self) -> f64

The distance between the top and bottom edges of this rectangle.

Source

pub fn size(&self) -> Size

The distance between the upper-left corner and the lower-right corner of this rectangle.

Source

pub fn has_nan(&self) -> bool

Whether any of the dimensions are NaN.

Source

pub fn is_infinite(&self) -> bool

Whether any of the coordinates of this rectangle are equal to positive infinity.

Source

pub fn is_finite(&self) -> bool

Whether all coordinates of this rectangle are finite.

Source

pub fn is_empty(&self) -> bool

Whether this rectangle encloses a non-zero area. Negative areas are considered empty.

Source

pub fn shift(&self, offset: Offset) -> Rect

Returns a new rectangle translated by the given offset.

To translate a rectangle by separate x and y components rather than by an Offset, consider translate.

Source

pub fn translate(&self, translate_x: f64, translate_y: f64) -> Rect

Returns a new rectangle with translateX added to the x components and translateY added to the y components.

To translate a rectangle by an Offset rather than by separate x and y components, consider shift.

Source

pub fn inflate(&self, delta: f64) -> Rect

Returns a new rectangle with edges moved outwards by the given delta.

Source

pub fn deflate(&self, delta: f64) -> Rect

Returns a new rectangle with edges moved inwards by the given delta.

Source

pub fn intersect(&self, other: Rect) -> Rect

Returns a new rectangle that is the intersection of the given rectangle and this rectangle. The two rectangles must overlap for this to be meaningful. If the two rectangles do not overlap, then the resulting Rect will have a negative width or height.

Source

pub fn expand_to_include(&self, other: Rect) -> Rect

Returns a new rectangle which is the bounding box containing this rectangle and the given rectangle.

Source

pub fn overlaps(&self, other: Rect) -> bool

Whether other has a nonzero area of overlap with this rectangle.

Source

pub fn shortest_side(&self) -> f64

The lesser of the magnitudes of the width and the height of this rectangle.

Source

pub fn longest_side(&self) -> f64

The greater of the magnitudes of the width and the height of this rectangle.

Source

pub fn top_left(&self) -> Offset

The offset to the intersection of the top and left edges of this rectangle.

See also Size::top_left.

Source

pub fn top_center(&self) -> Offset

The offset to the center of the top edge of this rectangle.

See also Size::top_center.

Source

pub fn top_right(&self) -> Offset

The offset to the intersection of the top and right edges of this rectangle.

See also Size::top_right.

Source

pub fn center_left(&self) -> Offset

The offset to the center of the left edge of this rectangle.

See also Size::center_left.

Source

pub fn center(&self) -> Offset

The offset to the point halfway between the left and right and the top and bottom edges of this rectangle.

See also Size::center.

Source

pub fn center_right(&self) -> Offset

The offset to the center of the right edge of this rectangle.

See also Size::center_right.

Source

pub fn bottom_left(&self) -> Offset

The offset to the intersection of the bottom and left edges of this rectangle.

See also Size::bottom_left.

Source

pub fn bottom_center(&self) -> Offset

The offset to the center of the bottom edge of this rectangle.

See also Size::bottom_center.

Source

pub fn bottom_right(&self) -> Offset

The offset to the intersection of the bottom and right edges of this rectangle.

See also Size::bottom_right.

Source

pub fn contains(&self, offset: Offset) -> bool

Whether the point specified by the given offset (which is assumed to be relative to the origin) lies between the left and right and the top and bottom edges of this rectangle.

Rectangles include their top and left edges but exclude their bottom and right edges.

Source

pub fn lerp(a: Option<Rect>, b: Option<Rect>, t: f64) -> Option<Rect>

Linearly interpolate between two rectangles.

If either rect is null, Rect::ZERO is used as a substitute.

The t argument represents position on the timeline, with 0.0 meaning that the interpolation has not started, returning a (or something equivalent to a), 1.0 meaning that the interpolation has finished, returning b (or something equivalent to b), and values in between meaning that the interpolation is at the relevant point on the timeline between a and b. The interpolation can be extrapolated beyond 0.0 and 1.0, so negative values and values greater than 1.0 are valid (and can easily be generated by curves such as Curves.elasticInOut).

Values for t are usually obtained from an Animation<double>, such as an AnimationController.

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 From<Rect> for Rect

Source§

fn from(rect: Rect) -> Rect

Converts to this type from the input type.
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 StructuralPartialEq for Rect

Auto Trait Implementations§

§

impl Freeze 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,