#[repr(C)]pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
An axis-aligned rectangle defined by its top-left corner, width, and height.
Uses the screen-space convention: Y increases downward.
Fields§
§x: f32X coordinate of the top-left corner.
y: f32Y coordinate of the top-left corner.
w: f32Width of the rectangle.
h: f32Height of the rectangle.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self
pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Self
Create a new rectangle from position and size.
Sourcepub const fn from_min_max(min: Vec2, max: Vec2) -> Self
pub const fn from_min_max(min: Vec2, max: Vec2) -> Self
Create a rectangle from min and max corner points.
Sourcepub const fn centered(center: Vec2, size: Vec2) -> Self
pub const fn centered(center: Vec2, size: Vec2) -> Self
Create a rectangle centered at center with the given size.
Sourcepub fn bottom_left(self) -> Vec2
pub fn bottom_left(self) -> Vec2
Bottom-left corner.
Sourcepub fn contains_rect(self, other: Rect) -> bool
pub fn contains_rect(self, other: Rect) -> bool
Check if this rectangle fully contains another.
Sourcepub fn overlaps(self, other: Rect) -> bool
pub fn overlaps(self, other: Rect) -> bool
Check if two rectangles overlap (AABB intersection test).
Sourcepub fn intersection(self, other: Rect) -> Option<Rect>
pub fn intersection(self, other: Rect) -> Option<Rect>
Compute the intersection rectangle, or None if they don’t overlap.
Sourcepub fn with_center(self, center: Vec2) -> Rect
pub fn with_center(self, center: Vec2) -> Rect
Move the rectangle so its center is at center.
Sourcepub fn translated(self, offset: Vec2) -> Rect
pub fn translated(self, offset: Vec2) -> Rect
Translate the rectangle by an offset.
Sourcepub fn closest_point(self, point: Vec2) -> Vec2
pub fn closest_point(self, point: Vec2) -> Vec2
Closest point inside the rectangle to the given point.
Sourcepub fn aspect_ratio(self) -> f32
pub fn aspect_ratio(self) -> f32
Aspect ratio (width / height).
Trait Implementations§
impl Copy for Rect
impl Pod for Rect
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§
impl<T> AnyBitPattern for Twhere
T: Pod,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.