pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
A 2D rectangle, defined by its top-left corner, width and height.
Fields§
§x: f32The x-coordinate of the top-left corner.
y: f32The y-coordinate of the top-left corner.
w: f32The width of the Rect, going to the right.
h: f32The height of the Rect, going down.
Implementations§
Source§impl Rect
impl Rect
Sourcepub const fn new(x: f32, y: f32, w: f32, h: f32) -> Rect
pub const fn new(x: f32, y: f32, w: f32, h: f32) -> Rect
Creates a new rectangle from its top-left corner, width and height.
§Arguments:
x- x-coordinate of the top-left corner.y- y-coordinate of the top-left corner.w- width of theRect, going to the right.h- height of theRect, going down.
Sourcepub const fn scale(&mut self, sx: f32, sy: f32)
pub const fn scale(&mut self, sx: f32, sy: f32)
Scales the Rect by a factor of (sx, sy),
growing towards the bottom-left.
Sourcepub const fn overlaps(&self, other: &Rect) -> bool
pub const fn overlaps(&self, other: &Rect) -> bool
Checks whether the Rect overlaps another Rect.
Sourcepub const fn combine_with(self, other: Rect) -> Rect
pub const fn combine_with(self, other: Rect) -> Rect
Returns a new Rect that includes all points of these two Rects.
Sourcepub const fn intersect(&self, other: Rect) -> Option<Rect>
pub const fn intersect(&self, other: Rect) -> Option<Rect>
Returns an intersection rect if there is any intersection.
Sourcepub fn normalized(&self) -> Rect
pub fn normalized(&self) -> Rect
Returns a normalized rect where width and height are guaranteed to be positive.
Trait Implementations§
impl Copy 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§
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
Mutably borrows from an owned value. Read more