Skip to main content

Rect

Struct Rect 

Source
pub struct Rect {
    pub min: Pos2,
    pub max: Pos2,
}
Expand description

An axis-aligned rectangle, min its left-top corner and max its right-bottom one.

A rect with max < min on either axis is negative: Rect::NOTHING is the deliberate case, the seed a bounding box accumulates from, and Rect::area and the containment tests are written to behave sensibly on it. There is no Default: a zero rect and an empty bounding box are different intentions, so the caller says which.

Fields§

§min: Pos2

One corner, usually the left-top one.

§max: Pos2

The opposing corner, usually the right-bottom one.

Implementations§

Source§

impl Rect

Source

pub const EVERYTHING: Self

Contains every point.

Source

pub const NOTHING: Self

The inverse of Self::EVERYTHING, containing no point. The seed a bounding box grows from: NOTHING.union(r) == r.

Source

pub const ZERO: Self

Source

pub const fn from_min_max(min: Pos2, max: Pos2) -> Self

Source

pub fn from_min_size(min: Pos2, size: Vec2) -> Self

Left-top corner plus a size, stretching right-down.

Source

pub fn from_center_size(center: Pos2, size: Vec2) -> Self

Source

pub fn from_two_pos(a: Pos2, b: Pos2) -> Self

The bounding rect of the two points, in either order.

Source

pub const fn from_pos(point: Pos2) -> Self

A zero-sized rect at a point.

Source

pub fn from_points(points: &[Pos2]) -> Self

The bounding rect of the points; Self::NOTHING when there are none.

Source

pub fn from_x_y_ranges(x_range: Rangef, y_range: Rangef) -> Self

Source

pub fn expand(self, amnt: f32) -> Self

Grow by amnt on all four sides, keeping the center.

Source

pub fn expand2(self, amnt: Vec2) -> Self

Grow per-axis, keeping the center.

Source

pub fn shrink(self, amnt: f32) -> Self

Shrink by amnt on all four sides, keeping the center.

Source

pub fn shrink2(self, amnt: Vec2) -> Self

Shrink per-axis, keeping the center.

Source

pub fn translate(self, amnt: Vec2) -> Self

Source

pub fn intersects(self, other: Self) -> bool

Source

pub fn set_width(&mut self, w: f32)

Keeps min.

Source

pub fn set_height(&mut self, h: f32)

Keeps min.

Source

pub fn set_center(&mut self, center: Pos2)

Keeps the size.

Source

pub fn contains(&self, p: Pos2) -> bool

Source

pub fn contains_rect(&self, other: Self) -> bool

Source

pub fn clamp(&self, p: Pos2) -> Pos2

p clamped inside the rect.

Source

pub fn extend_with(&mut self, p: Pos2)

Source

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

The smallest rect containing both.

Source

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

The area covered by both. Negative (see Rect) when they are disjoint.

Source

pub fn center(&self) -> Pos2

Source

pub fn size(&self) -> Vec2

Source

pub fn width(&self) -> f32

Can be negative.

Source

pub fn height(&self) -> f32

Can be negative.

Source

pub fn aspect_ratio(&self) -> f32

Width / height: below 1 portrait, above 1 landscape.

Source

pub fn area(&self) -> f32

Zero rather than negative for a negative rect.

Source

pub fn is_negative(&self) -> bool

width < 0 || height < 0

Source

pub fn is_positive(&self) -> bool

width > 0 && height > 0

Source

pub fn is_finite(&self) -> bool

Source

pub fn x_range(&self) -> Rangef

Source

pub fn y_range(&self) -> Rangef

Source§

impl Rect

Named edges and corners, assuming the origin is towards left-top.

Source

pub fn left(&self) -> f32

Source

pub fn right(&self) -> f32

Source

pub fn top(&self) -> f32

Source

pub fn bottom(&self) -> f32

Source

pub fn left_top(&self) -> Pos2

Source

pub fn center_top(&self) -> Pos2

Source

pub fn right_top(&self) -> Pos2

Source

pub fn left_center(&self) -> Pos2

Source

pub fn right_center(&self) -> Pos2

Source

pub fn left_bottom(&self) -> Pos2

Source

pub fn center_bottom(&self) -> Pos2

Source

pub fn right_bottom(&self) -> Pos2

Trait Implementations§

Source§

impl BitOr for Rect

Source§

type Output = Rect

The resulting type after applying the | operator.
Source§

fn bitor(self, other: Self) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign for Rect

Source§

fn bitor_assign(&mut self, other: Self)

Performs the |= operation. Read more
Source§

impl Clone for Rect

Source§

fn clone(&self) -> Rect

Returns a duplicate 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 Debug for Rect

Source§

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

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

impl<'de> Deserialize<'de> for Rect

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. 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 Div<f32> for Rect

Source§

type Output = Rect

The resulting type after applying the / operator.
Source§

fn div(self, factor: f32) -> Self

Performs the / operation. Read more
Source§

impl From<[Pos2; 2]> for Rect

Source§

fn from([min, max]: [Pos2; 2]) -> Self

Converts to this type from the input type.
Source§

impl Mul<Rect> for f32

Source§

type Output = Rect

The resulting type after applying the * operator.
Source§

fn mul(self, r: Rect) -> Rect

Performs the * operation. Read more
Source§

impl Mul<f32> for Rect

Source§

type Output = Rect

The resulting type after applying the * operator.
Source§

fn mul(self, factor: f32) -> Self

Performs the * operation. 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 · 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 Serialize for Rect

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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.

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,