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: f32
X coordinate of the left edge of the rect.
y: f32
Y coordinate of the top edge of the rect.
w: f32
Total width of the rect
h: f32
Total 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 fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self
pub fn new_i32(x: i32, y: i32, w: i32, h: i32) -> Self
Create a new rect from i32
coordinates.
Loses precision if the integers are too big to fit
in f32
’s.
sourcepub fn contains<P>(&self, point: P) -> boolwhere
P: Into<Point2<f32>>,
pub fn contains<P>(&self, point: P) -> boolwhere P: Into<Point2<f32>>,
Checks whether the Rect
contains a Point
sourcepub fn overlaps_circle(
&self,
point: impl Into<Point2<f32>>,
radius: f32
) -> bool
pub fn overlaps_circle( &self, point: impl Into<Point2<f32>>, radius: f32 ) -> bool
Checks whether the Rect
overlaps a circle.
sourcepub fn translate<V>(&mut self, offset: V)where
V: Into<Vector2<f32>>,
pub fn translate<V>(&mut self, offset: V)where V: Into<Vector2<f32>>,
Translates the Rect
by an offset of (x, y)
sourcepub fn move_to<P>(&mut self, destination: P)where
P: Into<Point2<f32>>,
pub fn move_to<P>(&mut self, destination: P)where P: Into<Point2<f32>>,
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 Rect
s.
Trait Implementations§
source§impl AbsDiffEq<Rect> for Rect
impl AbsDiffEq<Rect> 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 PartialEq<Rect> for Rect
impl PartialEq<Rect> for Rect
source§impl RelativeEq<Rect> for Rect
impl RelativeEq<Rect> 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 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
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
source§impl<T> HasMut<T> for T
impl<T> HasMut<T> for T
source§fn retrieve_mut(&mut self) -> &mut T
fn retrieve_mut(&mut self) -> &mut T
Method to retrieve the context type as mutable.