Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub x: u16,
    pub y: u16,
    pub width: u16,
    pub height: u16,
}
Expand description

An axis-aligned rectangle in the cell grid.

The rectangle is anchored at its top-left corner (x, y) and extends width cells to the right and height cells down. The right and bottom edges are exclusive: a cell at (x, y) is contained iff left() <= x < right() and top() <= y < bottom().

Fields§

§x: u16

Column of the top-left corner.

§y: u16

Row of the top-left corner.

§width: u16

Width in cells.

§height: u16

Height in cells.

Implementations§

Source§

impl Rect

Source

pub const ZERO: Self

An empty rectangle at the origin.

Source

pub const fn new(x: u16, y: u16, width: u16, height: u16) -> Self

Create a rectangle from (x, y, width, height).

width and height are clamped so that right() and bottom() stay within u16.

Source

pub const fn area(self) -> u32

Area in cells.

Source

pub const fn is_empty(self) -> bool

True when the rectangle has zero area.

Source

pub const fn left(self) -> u16

Inclusive left edge (column of the leftmost cell).

Source

pub const fn right(self) -> u16

Exclusive right edge (one past the rightmost column).

Source

pub const fn top(self) -> u16

Inclusive top edge (row of the topmost cell).

Source

pub const fn bottom(self) -> u16

Exclusive bottom edge (one past the bottommost row).

Source

pub const fn position(self) -> Position

The top-left corner as a Position.

Source

pub fn contains(self, pos: impl Into<Position>) -> bool

True when pos lies inside the rectangle.

Source

pub fn intersection(self, other: Self) -> Self

The largest rectangle contained in both self and other.

Source

pub fn union(self, other: Self) -> Self

The smallest rectangle that contains both self and other.

Trait Implementations§

Source§

impl Bounded for Rect

Source§

fn bounds(&self) -> Rect

Return the valid region in this value’s own coordinate space. Read more
Source§

fn width(&self) -> u16

Return the width of Self::bounds in terminal cell columns. Read more
Source§

fn height(&self) -> u16

Return the height of Self::bounds in terminal cell rows. Read more
Source§

fn contains(&self, pos: Position) -> bool

Test whether a position lies inside Self::bounds. Read more
Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

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 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 Display for Rect

Source§

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

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

impl From<(u16, u16, u16, u16)> for Rect

Source§

fn from((x, y, width, height): (u16, u16, u16, u16)) -> Self

Converts to this type from the input type.
Source§

impl From<Rect> for (u16, u16, u16, u16)

Source§

fn from(r: Rect) -> Self

Converts to this type from the input type.
Source§

impl From<Rect> for Position

Source§

fn from(r: Rect) -> Self

The top-left corner of the rectangle.

Source§

impl From<Rect> for Size

Source§

fn from(r: Rect) -> Self

The rectangle’s width by height, dropping its position.

Source§

impl Hash for Rect

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 Rect

Source§

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

Source§

impl Eq 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 UnsafeUnpin 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<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.

§

impl<T> ToCompactString for T
where T: Display,

§

fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>

Fallible version of [ToCompactString::to_compact_string()] Read more
§

fn to_compact_string(&self) -> CompactString

Converts the given value to a [CompactString]. 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<T> ErasedDestructor for T
where T: 'static,