Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub x: f32,
    pub y: f32,
    pub w: f32,
    pub h: f32,
}
Expand description

A 2D rectangle, defined by its top-left corner, width and height.

Fields§

§x: f32

The x-coordinate of the top-left corner.

§y: f32

The y-coordinate of the top-left corner.

§w: f32

The width of the Rect, going to the right.

§h: f32

The height of the Rect, going down.

Implementations§

Source§

impl Rect

Source

pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Rect

Creates a new rectangle from its top-left corner, width and height.

§Arguments:
  • x - x-coordinate of the top-left corner.
  • y - y-coordinate of the top-left corner.
  • w - width of the Rect, going to the right.
  • h - height of the Rect, going down.
Source

pub const fn point(&self) -> Vec2

Returns the top-left corner of the Rect.

Source

pub const fn size(&self) -> Vec2

Returns the size (width and height) of the Rect.

Source

pub const fn center(&self) -> Vec2

Returns the center position of the Rect.

Source

pub const fn left(&self) -> f32

Returns the left edge of the Rect.

Source

pub const fn right(&self) -> f32

Returns the right edge of the Rect.

Source

pub const fn top(&self) -> f32

Returns the top edge of the Rect.

Source

pub const fn bottom(&self) -> f32

Returns the bottom edge of the Rect.

Source

pub const fn move_to(&mut self, destination: Vec2)

Moves the Rect’s origin to (x, y).

Source

pub const fn scale(&mut self, sx: f32, sy: f32)

Scales the Rect by a factor of (sx, sy), growing towards the bottom-left.

Source

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

Checks whether the Rect contains a Point.

Source

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

Checks whether the Rect overlaps another Rect.

Source

pub const fn combine_with(self, other: Rect) -> Rect

Returns a new Rect that includes all points of these two Rects.

Source

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

Returns an intersection rect if there is any intersection.

Source

pub const fn offset(self, offset: Vec2) -> Rect

Translate rect origin by offset vector.

Source

pub fn normalized(&self) -> Rect

Returns a normalized rect where width and height are guaranteed to be positive.

Trait Implementations§

Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Rect

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more