Skip to main content

Rectangle

Struct Rectangle 

Source
pub struct Rectangle<T = f32> { /* private fields */ }
Expand description

A struct representing an axis-aligned rectangle. Two points are stored: the top left vertex, and the bottom right vertex.

Implementations§

Source§

impl<T> Rectangle<T>

Source

pub const fn new(top_left: Vector2<T>, bottom_right: Vector2<T>) -> Self

Constructs a new Rectangle. The top left vertex must be above and to the left of the bottom right vertex.

Source

pub fn from_tuples(top_left: (T, T), bottom_right: (T, T)) -> Self

Constructs a new Rectangle. The top left vertex must be above and to the left of the bottom right vertex.

Source

pub const fn top_left(&self) -> &Vector2<T>

Returns a reference to the top left vertex.

Source

pub const fn bottom_right(&self) -> &Vector2<T>

Returns a reference to the bottom right vertex.

Source§

impl<T: Copy> Rectangle<T>

Source

pub fn rounded(&self, radius: T) -> RoundedRectangle<T>

Returns a new RoundedRectangle which has the same sizes of Self and a radius of T

Source

pub fn top_right(&self) -> Vector2<T>

Returns a vector representing the top right vertex.

Source

pub fn bottom_left(&self) -> Vector2<T>

Returns a vector representing the bottom left vertex.

Source

pub fn left(&self) -> T

Returns the x value of the left border

Source

pub fn right(&self) -> T

Returns the x value of the right border

Source

pub fn top(&self) -> T

Returns the y value of the top border

Source

pub fn bottom(&self) -> T

Returns the y value of the bottom border

Source§

impl<T: Sub<Output = T> + Copy> Rectangle<T>

Source

pub fn width(&self) -> T

Returns the width of the rectangle.

Source

pub fn height(&self) -> T

Returns the height of the rectangle.

Source

pub fn size(&self) -> Vector2<T>

Returns a Vector2 containing the width and height of the rectangle.

Source§

impl<T: PartialOrd<T> + Copy> Rectangle<T>

Source

pub fn contains(&self, point: Vector2<T>) -> bool

Returns true if the specified point is inside this rectangle. This is inclusive of the top and left coordinates, and exclusive of the bottom and right coordinates.

Source§

impl<T: PartialOrd + Copy> Rectangle<T>

Source

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

Finds the intersection of two rectangles – in other words, the area that is common to both of them.

If there is no common area between the two rectangles, then this function will return None.

Source§

impl<T: PrimitiveZero> Rectangle<T>

Source

pub const ZERO: Rectangle<T>

A constant representing a rectangle with position (0, 0) and zero area. Each component is set to zero.

Source§

impl<T: PartialEq> Rectangle<T>

Source

pub fn is_zero_area(&self) -> bool

Returns true if the rectangle has zero area.

Source§

impl<T: PartialOrd> Rectangle<T>

Source

pub fn is_positive_area(&self) -> bool

Returns true if the rectangle has an area greater than zero.

Source§

impl<T: Copy> Rectangle<T>
where Vector2<T>: Add<Output = Vector2<T>>,

Source

pub fn with_offset(&self, offset: impl Into<Vector2<T>>) -> Self

Returns a new rectangle, whose vertices are offset relative to the current rectangle by the specified amount. This is equivalent to adding the specified vector to each vertex.

Source§

impl<T: Copy> Rectangle<T>
where Vector2<T>: Sub<Output = Vector2<T>>,

Source

pub fn with_negative_offset(&self, offset: impl Into<Vector2<T>>) -> Self

Returns a new rectangle, whose vertices are negatively offset relative to the current rectangle by the specified amount. This is equivalent to subtracting the specified vector to each vertex.

Source§

impl<T: AsPrimitive<f32>> Rectangle<T>

Source

pub fn into_f32(self) -> Rectangle<f32>

Returns a new rectangle where the coordinates have been cast to f32 values, using the as operator.

Source§

impl<T: AsPrimitive<f32> + Copy> Rectangle<T>

Source

pub fn as_f32(&self) -> Rectangle<f32>

Returns a new rectangle where the coordinates have been cast to f32 values, using the as operator.

Trait Implementations§

Source§

impl<T> AsRef<Rectangle<T>> for Rectangle<T>

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Clone> Clone for Rectangle<T>

Source§

fn clone(&self) -> Rectangle<T>

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<T: Debug> Debug for Rectangle<T>

Source§

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

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

impl<T: Eq> Eq for Rectangle<T>

Source§

impl<T: Copy> From<&Rect<T>> for Rectangle<T>

Source§

fn from(rect: &Rect<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Rect<T>> for Rectangle<T>

Source§

fn from(rect: Rect<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for Rectangle<T>

Source§

fn eq(&self, other: &Rectangle<T>) -> bool

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

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for Rectangle<T>

Auto Trait Implementations§

§

impl<T> Freeze for Rectangle<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Rectangle<T>
where T: RefUnwindSafe,

§

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

§

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

§

impl<T> Unpin for Rectangle<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Rectangle<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Rectangle<T>
where T: UnwindSafe,

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 for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> 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> 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 = 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<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
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