Struct Rect

Source
pub struct Rect<T> {
    pub origin: Vec2<T>,
    pub size: Vec2<T>,
}
Expand description

A rectangle on the integer grid.

Fields§

§origin: Vec2<T>§size: Vec2<T>

Implementations§

Source§

impl<T> Rect<T>

Source

pub const fn new(origin: Vec2<T>, size: Vec2<T>) -> Self

Creates a new rectangle.

Source§

impl<T> Rect<T>
where T: Copy,

Source

pub const fn width(self) -> T

The rectangle’s width.

Source

pub const fn height(self) -> T

The rectangle’s height.

Source

pub const fn top_left(self) -> Vec2<T>

Fetches the top-left corner of the rectangle, i.e. the origin.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Copy,

Source

pub fn bottom_right(self) -> Vec2<T>

Fetches the bottom-right corner of the rectangle.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Copy + Zero,

Source

pub fn bottom_left(self) -> Vec2<T>

Fetches the bottom-left corner of the rectangle.

Source

pub fn top_right(self) -> Vec2<T>

Fetches the top-right corner of the rectangle.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Div<Output = T> + Copy + Zero + Unity,

Source

pub fn top_center(self) -> Vec2<T>

Fetches the top-center position of the rectangle.

Source

pub fn center_left(self) -> Vec2<T>

Fetches the left-center position of the rectangle.

Source

pub fn center_right(self) -> Vec2<T>

Fetches the right-center position of the rectangle.

Source

pub fn bottom_center(self) -> Vec2<T>

Fetches the bottom-center position of the rectangle.

Source

pub fn center(self) -> Vec2<T>

Fetches the center position of the rectangle.

Source§

impl<T> Rect<T>
where T: Mul<Output = T> + Copy,

Source

pub fn area(self) -> T

The rectangle’s area.

Source§

impl<T> Rect<T>
where T: RemEuclid + Copy,

Source

pub fn wrap(self, pos: Vec2<T>) -> Vec2<T>

Wraps a value to the rectangle’s bounds.

Source§

impl<T> Rect<T>
where T: Zero + Eq + Copy,

Source

pub fn is_empty(self) -> bool

Whether this rectangle is empty.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Copy,

Source

pub fn x_range(self) -> Range<T>

The range of x values.

Source

pub fn y_range(self) -> Range<T>

The range of y values.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Copy, Range<T>: IteratorRandom<Item = T>,

Source

pub fn sample_random_with(self, rng: &mut impl Rng) -> Option<Vec2<T>>

Samples a random position within the rectangle with the given rng.

Source

pub fn sample_random(self) -> Option<Vec2<T>>

Samples a random position within the rectangle.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Ord + Copy,

Source

pub fn contains(self, pos: Vec2<T>) -> bool

Checks whether the rectangle contains the given position.

Source

pub fn intersects(self, other: Rect<T>) -> bool

Checks whether the rectangle intersects the given rectangle.

Source§

impl<T> Rect<T>
where T: Add<Output = T> + Sub<Output = T> + TryInto<usize> + Ord + Copy, T::Error: Debug,

Source

pub fn index_of(self, pos: Vec2<T>) -> usize

Converts a position to an index.

Trait Implementations§

Source§

impl<T: Clone> Clone for Rect<T>

Source§

fn clone(&self) -> Rect<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 Rect<T>

Source§

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

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

impl<T: Hash> Hash for Rect<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for Rect<T>

Source§

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

Source§

impl<T: Eq> Eq for Rect<T>

Source§

impl<T> StructuralPartialEq for Rect<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Rect<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<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 = 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