pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
Fields§
§x: f32x coordinate of top-left corner
y: f32y coordinate of top-left corner
w: f32width
h: f32height
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 top-left corner and size.
Sourcepub fn from_center(center: Vec2, half_size: Vec2) -> Self
pub fn from_center(center: Vec2, half_size: Vec2) -> Self
create a rectangle from center point and half-size extents.
Sourcepub fn contains(&self, point: Vec2) -> bool
pub fn contains(&self, point: Vec2) -> bool
check if a point lies inside this rectangle.
inclusive of all edges (touching counts as inside). contrast with intersects,
which is exclusive (touching edges do not count as overlap).
Sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
check if this rectangle overlaps another.
exclusive of touching edges (two rects that share only an edge do not overlap). contrast with
contains, which is inclusive.
Sourcepub const fn bottom_right(&self) -> Vec2
pub const fn bottom_right(&self) -> Vec2
get the bottom-right corner position.
Sourcepub fn inflate(&mut self, dx: f32, dy: f32)
pub fn inflate(&mut self, dx: f32, dy: f32)
expand or shrink the rect by the given deltas on all sides.
Sourcepub fn clamp(&mut self, within: &Self)
pub fn clamp(&mut self, within: &Self)
constrain this rect to lie fully within another rect. clamps both position and size so the right/bottom edges don’t exceed the boundary.
Sourcepub fn collide_point(&self, point: Vec2) -> bool
pub fn collide_point(&self, point: Vec2) -> bool
alias for Rect::contains — point collision check.
Sourcepub fn collide_rect(&self, other: &Self) -> bool
pub fn collide_rect(&self, other: &Self) -> bool
alias for Rect::intersects — rect collision check.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.