pub struct Rect {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
}Expand description
A rectangle defined by position and size.
Fields§
§x: f32X position of top-left corner
y: f32Y position of top-left corner
width: f32Width
height: f32Height
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn from_points(top_left: Point, bottom_right: Point) -> Self
pub fn from_points(top_left: Point, bottom_right: Point) -> Self
Create from two corner points.
Sourcepub fn bottom_left(&self) -> Point
pub fn bottom_left(&self) -> Point
Get bottom-left corner.
Sourcepub fn bottom_right(&self) -> Point
pub fn bottom_right(&self) -> Point
Get bottom-right corner.
Sourcepub fn contains_point(&self, point: &Point) -> bool
pub fn contains_point(&self, point: &Point) -> bool
Check if a point is inside the rectangle (inclusive).
Sourcepub fn intersects(&self, other: &Self) -> bool
pub fn intersects(&self, other: &Self) -> bool
Check if this rectangle intersects another.
Sourcepub fn intersection(&self, other: &Self) -> Option<Self>
pub fn intersection(&self, other: &Self) -> Option<Self>
Calculate intersection with another rectangle.
Sourcepub fn inset(&self, amount: f32) -> Self
pub fn inset(&self, amount: f32) -> Self
Create a new rectangle inset by the given amount on all sides.
Sourcepub const fn with_origin(&self, origin: Point) -> Self
pub const fn with_origin(&self, origin: Point) -> Self
Create a new rectangle with the given position.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Rect
impl<'de> Deserialize<'de> for Rect
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
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 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
Read this value from the supplied reader. Same as
ReadEndian::read_from_little_endian().