Struct speedy2d::shape::Rectangle

source ·
#[repr(C)]
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 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§

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

source§

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

Returns a copy 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<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: 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<Rectangle<T>> for Rectangle<T>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

source§

impl<T> StructuralEq for Rectangle<T>

source§

impl<T> StructuralPartialEq for Rectangle<T>

Auto Trait Implementations§

§

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

Blanket Implementations§

source§

impl<T> Any for Twhere
    T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
    T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
    U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere
    T: Clone,

§

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 Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
    U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.