pub struct Rect {
pub x: f32,
pub y: f32,
pub w: f32,
pub h: f32,
}Expand description
A simple 2D rectangle.
The origin of the rectangle is at the top-left, with x increasing to the right and y increasing down.
Fields§
§x: f32X coordinate of the left edge of the rect.
y: f32Y coordinate of the top edge of the rect.
w: f32Total width of the rect
h: f32Total height of the rect.
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn fraction(x: f32, y: f32, w: f32, h: f32, reference: &Rect) -> Rect
pub fn fraction(x: f32, y: f32, w: f32, h: f32, reference: &Rect) -> Rect
Creates a new Rect a la Love2D’s love.graphics.newQuad,
as a fraction of the reference rect’s size.
Sourcepub const fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self
pub const fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self
Create a new rect from i32 coordinates.
Sourcepub fn contains<P: Into<Point2<f32>>>(&self, point: P) -> bool
pub fn contains<P: Into<Point2<f32>>>(&self, point: P) -> bool
Checks whether the Rect contains a Point
Sourcepub fn translate<V: Into<Vector2<f32>>>(&mut self, offset: V)
pub fn translate<V: Into<Vector2<f32>>>(&mut self, offset: V)
Translates the Rect by an offset of (x, y)
Sourcepub fn move_to<P: Into<Point2<f32>>>(&mut self, destination: P)
pub fn move_to<P: Into<Point2<f32>>>(&mut self, destination: P)
Moves the Rect’s origin to (x, y)
Sourcepub fn scale(&mut self, sx: f32, sy: f32)
pub fn scale(&mut self, sx: f32, sy: f32)
Scales the Rect by a factor of (sx, sy),
growing towards the bottom-left
Sourcepub fn combine_with(self, other: Rect) -> Rect
pub fn combine_with(self, other: Rect) -> Rect
Returns a new Rect that includes all points of these two Rects.
Trait Implementations§
Source§impl AbsDiffEq for Rect
impl AbsDiffEq for Rect
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
The default tolerance to use when testing values that are close together. Read more
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
A test for equality that uses the absolute difference to compute the approximate
equality of two numbers.
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of
AbsDiffEq::abs_diff_eq.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
Source§impl RelativeEq for Rect
impl RelativeEq for Rect
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
A test for equality that uses a relative comparison if the values are far apart.
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
The inverse of
RelativeEq::relative_eq.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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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 more