Rect

Struct Rect 

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

A simple 2D rectangle.

The origin of the rectangle is at the top-left, with x increasing to the right and y increasing down.

Fields§

§x: f32

X coordinate of the left edge of the rect.

§y: f32

Y coordinate of the top edge of the rect.

§w: f32

Total width of the rect

§h: f32

Total height of the rect.

Implementations§

Source§

impl Rect

Source

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

Create a new Rect.

Source

pub fn fraction(x: f32, y: f32, w: f32, h: f32, reference: &Rect) -> Rect

Creates a new Rect a la Love2D’s love.graphics.newQuad, as a fraction of the reference rect’s size.

Source

pub const fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self

Create a new rect from i32 coordinates.

Source

pub const fn zero() -> Self

Create a new Rect with all values zero.

Source

pub const fn one() -> Self

Creates a new Rect at 0,0 with width and height 1.

Source

pub fn point(&self) -> Point2<f32>

Gets the Rect’s x and y coordinates as a Point2.

Source

pub fn center(&self) -> Point2<f32>

Returns the center of the Rect as a Point2.

Source

pub fn left(&self) -> f32

Returns the left edge of the Rect

Source

pub fn right(&self) -> f32

Returns the right edge of the Rect

Source

pub fn top(&self) -> f32

Returns the top edge of the Rect

Source

pub fn bottom(&self) -> f32

Returns the bottom edge of the Rect

Source

pub fn contains<P: Into<Point2<f32>>>(&self, point: P) -> bool

Checks whether the Rect contains a Point

Source

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

Checks whether the Rect overlaps another Rect

Source

pub fn translate<V: Into<Vector2<f32>>>(&mut self, offset: V)

Translates the Rect by an offset of (x, y)

Source

pub fn move_to<P: Into<Point2<f32>>>(&mut self, destination: P)

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

Source

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

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

Source

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

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

Source

pub fn rotate(&mut self, rotation: f32)

Calculated the new Rect around the rotated one.

Trait Implementations§

Source§

impl AbsDiffEq for Rect

Source§

type Epsilon = f32

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
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

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<'de> Deserialize<'de> for Rect

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<[f32; 4]> for Rect

Source§

fn from(val: [f32; 4]) -> Self

Converts to this type from the input type.
Source§

impl From<Rect> for [f32; 4]

Source§

fn from(val: Rect) -> Self

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

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl Serialize for Rect

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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 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<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,