Skip to main content

RectU16

Struct RectU16 

Source
pub struct RectU16 {
    pub x0: u16,
    pub y0: u16,
    pub x1: u16,
    pub y1: u16,
}
Expand description

An axis-aligned rectangle with u16 coordinates, stored as two corners (x0, y0) and (x1, y1).

(x0, y0) is the top-left (minimum) corner and (x1, y1) is the bottom-right (maximum) corner. The rectangle is considered to be empty when x0 >= x1 or y0 >= y1.

Fields§

§x0: u16

The minimum x coordinate (left edge).

§y0: u16

The minimum y coordinate (top edge).

§x1: u16

The maximum x coordinate (right edge, exclusive).

§y1: u16

The maximum y coordinate (bottom edge, exclusive).

Implementations§

Source§

impl RectU16

Source

pub const ZERO: Self

A rectangle with all coordinates set to zero.

Source

pub const INVERTED: Self

An empty, maximally inverted rectangle, useful as a starting value for incremental union operations.

Has (x0, y0) = (u16::MAX, u16::MAX) and (x1, y1) = (0, 0).

Source

pub const fn new(x0: u16, y0: u16, x1: u16, y1: u16) -> Self

Create a new rectangle from its corner coordinates.

Source

pub const fn width(self) -> u16

The width of the rectangle (x1 - x0), saturating at zero.

Source

pub const fn height(self) -> u16

The height of the rectangle (y1 - y0), saturating at zero.

Source

pub const fn is_empty(self) -> bool

Returns true if the rectangle has zero area (x0 >= x1 or y0 >= y1).

Source

pub const fn contains(self, x: u16, y: u16) -> bool

Check if a point (x, y) is contained within this rectangle.

Returns true if x0 <= x < x1 and y0 <= y < y1.

Source

pub const fn intersect(self, other: Self) -> Self

Compute the intersection of two rectangles.

The result may have zero area if the rectangles do not overlap, but is never inverted.

Source

pub const fn expand(self, padding: PaddingU16) -> Self

Expand this rectangle by the given left, top, right, and bottom padding.

Source

pub fn relative_to_origin(self, origin: (u16, u16)) -> Self

Return this rectangle relative to origin, clamping negative coordinates to zero.

Source

pub fn shift(self, shift: (i32, i32)) -> Self

Return a shifted version of the rectangle, clamping negative coordinates to zero.

Source

pub const fn union(&mut self, other: Self)

Expand this rectangle to also cover other (union in place).

The union of self with a Self::INVERTED returns self.

Source

pub fn as_rect(self) -> Rect

Return the rect as a Rect.

Trait Implementations§

Source§

impl Clone for RectU16

Source§

fn clone(&self) -> RectU16

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 Debug for RectU16

Source§

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

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

impl From<RectU16> for SizeU16

Source§

fn from(rect: RectU16) -> Self

Converts to this type from the input type.
Source§

impl Hash for RectU16

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 PartialEq for RectU16

Source§

fn eq(&self, other: &RectU16) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 RectExt for RectU16

Source§

fn snap_to_tile_coordinates(self) -> Self

Snap the rect to whole tile coordinates.
Source§

impl Copy for RectU16

Source§

impl Eq for RectU16

Source§

impl StructuralPartialEq for RectU16

Auto Trait Implementations§

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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.