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: Pos2One corner, usually the left-top one.
max: Pos2The opposing corner, usually the right-bottom one.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const EVERYTHING: Self
pub const EVERYTHING: Self
Contains every point.
Sourcepub const NOTHING: Self
pub const NOTHING: Self
The inverse of Self::EVERYTHING, containing no point. The seed a
bounding box grows from: NOTHING.union(r) == r.
pub const ZERO: Self
pub const fn from_min_max(min: Pos2, max: Pos2) -> Self
Sourcepub fn from_min_size(min: Pos2, size: Vec2) -> Self
pub fn from_min_size(min: Pos2, size: Vec2) -> Self
Left-top corner plus a size, stretching right-down.
pub fn from_center_size(center: Pos2, size: Vec2) -> Self
Sourcepub fn from_two_pos(a: Pos2, b: Pos2) -> Self
pub fn from_two_pos(a: Pos2, b: Pos2) -> Self
The bounding rect of the two points, in either order.
Sourcepub fn from_points(points: &[Pos2]) -> Self
pub fn from_points(points: &[Pos2]) -> Self
The bounding rect of the points; Self::NOTHING when there are none.
pub fn from_x_y_ranges(x_range: Rangef, y_range: Rangef) -> Self
pub fn translate(self, amnt: Vec2) -> Self
pub fn intersects(self, other: Self) -> bool
Sourcepub fn set_height(&mut self, h: f32)
pub fn set_height(&mut self, h: f32)
Keeps min.
Sourcepub fn set_center(&mut self, center: Pos2)
pub fn set_center(&mut self, center: Pos2)
Keeps the size.
pub fn contains(&self, p: Pos2) -> bool
pub fn contains_rect(&self, other: Self) -> bool
pub fn extend_with(&mut self, p: Pos2)
Sourcepub fn intersect(self, other: Self) -> Self
pub fn intersect(self, other: Self) -> Self
The area covered by both. Negative (see Rect) when they are disjoint.
pub fn center(&self) -> Pos2
pub fn size(&self) -> Vec2
Sourcepub fn aspect_ratio(&self) -> f32
pub fn aspect_ratio(&self) -> f32
Width / height: below 1 portrait, above 1 landscape.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
width < 0 || height < 0
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
width > 0 && height > 0
pub fn is_finite(&self) -> bool
pub fn x_range(&self) -> Rangef
pub fn y_range(&self) -> Rangef
Source§impl Rect
Named edges and corners, assuming the origin is towards left-top.
impl Rect
Named edges and corners, assuming the origin is towards left-top.
pub fn left(&self) -> f32
pub fn right(&self) -> f32
pub fn top(&self) -> f32
pub fn bottom(&self) -> f32
pub fn left_top(&self) -> Pos2
pub fn center_top(&self) -> Pos2
pub fn right_top(&self) -> Pos2
pub fn left_center(&self) -> Pos2
pub fn right_center(&self) -> Pos2
pub fn left_bottom(&self) -> Pos2
pub fn center_bottom(&self) -> Pos2
pub fn right_bottom(&self) -> Pos2
Trait Implementations§
Source§impl BitOrAssign for Rect
impl BitOrAssign for Rect
Source§fn bitor_assign(&mut self, other: Self)
fn bitor_assign(&mut self, other: Self)
|= operation. Read more