pub struct Rectangle {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}Expand description
A rectangle defined by its top-left corner (x, y) and width and height.
Fields§
§x: f32§y: f32§width: f32§height: f32Implementations§
Source§impl Rectangle
impl Rectangle
Sourcepub fn translate(&self, delta: Vector2) -> Self
pub fn translate(&self, delta: Vector2) -> Self
Returns a new rectangle translated by the given vector.
Sourcepub fn scale(&self, origin: Vector2, scale: Vector2) -> Self
pub fn scale(&self, origin: Vector2, scale: Vector2) -> Self
Scales the rectangle relative to the given origin.
Sourcepub fn axis_dimension(&self, axis: Axis) -> f32
pub fn axis_dimension(&self, axis: Axis) -> f32
Returns the dimension (width or height) for the given axis.
Sourcepub fn contains_point(&self, point: Vector2) -> bool
pub fn contains_point(&self, point: Vector2) -> bool
Returns true if the point is inside the rectangle (inclusive).
Sourcepub fn offset_to(&self, point: Vector2) -> Vector2
pub fn offset_to(&self, point: Vector2) -> Vector2
Returns the signed offset from the point to the nearest edge.
Sourcepub fn intersects(&self, other: &Rectangle) -> bool
pub fn intersects(&self, other: &Rectangle) -> bool
Returns true if two rectangles intersect or touch at the edges.
Sourcepub fn intersection(&self, other: &Rectangle) -> Option<Rectangle>
pub fn intersection(&self, other: &Rectangle) -> Option<Rectangle>
Returns the intersection of two rectangles, or None if they do not overlap.
Trait Implementations§
impl Copy for Rectangle
impl StructuralPartialEq for Rectangle
Auto Trait Implementations§
impl Freeze for Rectangle
impl RefUnwindSafe for Rectangle
impl Send for Rectangle
impl Sync for Rectangle
impl Unpin for Rectangle
impl UnwindSafe for Rectangle
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