Skip to main content

Rect

Struct Rect 

Source
#[repr(C)]
pub struct Rect { pub x0: f32, pub y0: f32, pub x1: f32, pub y1: f32, }
Expand description

An axis-aligned rectangle in pixels, y down, stored as its four edges.

Edges, not origin plus size, so rectangles built from shared edges tile exactly: with half-open contains, a point on a shared edge belongs to exactly one of them, even after both are translated by the same amount. (Origin plus size recomputes x + width, which can miss the original edge by a rounding step.)

A rectangle whose right edge is not past its left (or bottom past top), or with a NaN edge, is empty and contains no point.

Fields§

§x0: f32

Left edge.

§y0: f32

Top edge.

§x1: f32

Right edge.

§y1: f32

Bottom edge.

Implementations§

Source§

impl Rect

Source

pub const EVERYTHING: Rect

Every point: what a clip that clips nothing is.

Source

pub fn new(x: f32, y: f32, width: f32, height: f32) -> Rect

The rectangle with top-left corner (x, y) and size width x height.

Source

pub fn from_edges(left: f32, top: f32, right: f32, bottom: f32) -> Rect

The rectangle spanning the given edges, in either order. NaN edges are kept, giving an empty rectangle rather than a silently different one.

Source

pub fn left(&self) -> f32

Left edge.

Source

pub fn top(&self) -> f32

Top edge.

Source

pub fn right(&self) -> f32

Right edge.

Source

pub fn bottom(&self) -> f32

Bottom edge.

Source

pub fn width(&self) -> f32

Distance between the left and right edges.

Source

pub fn height(&self) -> f32

Distance between the top and bottom edges.

Source

pub fn is_empty(&self) -> bool

Whether the rectangle covers no area (also true with a NaN edge).

Source

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

Whether point lies inside: left and top edges included, right and bottom not, so a point on an edge shared by two rectangles belongs to exactly one.

Source

pub fn translate(self, by: Point) -> Rect

The rectangle moved by by.

Source

pub fn to_xywh(self) -> [f32; 4]

[x, y, width, height], the layout GPU instances use.

Source

pub fn origin(&self) -> Point

The top-left corner.

Source

pub fn size(&self) -> Size

Width and height.

Source

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

The area both rectangles cover; empty if they do not overlap or either is empty.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

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<(), Error>

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

impl Default for Rect

Source§

fn default() -> Rect

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

impl PartialEq for Rect

Source§

fn eq(&self, other: &Rect) -> 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<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<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.