#[repr(C)]pub struct Rect<T: Number> { /* private fields */ }
Implementations
sourceimpl<N: Number> Rect<N>
impl<N: Number> Rect<N>
pub fn new(origin: impl Into<[N; 2]>, size: impl Into<[N; 2]>) -> Rect<N>
pub fn new_min_max(min: impl Into<[N; 2]>, max: impl Into<[N; 2]>) -> Rect<N>
pub fn zero() -> Rect<N>
sourcepub fn cast<NO: Number>(self) -> Rect<NO>
pub fn cast<NO: Number>(self) -> Rect<NO>
Casts the rectangle to another primitive unit, panicking if the unit cannot be represented.
sourcepub fn try_cast<NO: Number>(self) -> Option<Rect<NO>>
pub fn try_cast<NO: Number>(self) -> Option<Rect<NO>>
Same as Self::cast but returns None if the cast failed.
sourcepub fn intersects_rect(&self, other: Rect<N>) -> bool
pub fn intersects_rect(&self, other: Rect<N>) -> bool
Checks if self intersects other. In other words it check if any of these rectangles touch each other. This is very useful in cull testing.
Arguments
other
: The other rectangle to check intersection with.
returns: bool
Examples
use mathie::Rect;
let rect = Rect::one();
assert!(rect.intersects_rect(Rect::new([0.0, 0.0], [1.0, 1.0])));
assert!(rect.intersects_rect(Rect::new([0.4, 0.4], [0.2, 0.2])));
assert!(rect.intersects_rect(Rect::new([1.0, 1.0], [1.0, 1.0])));
assert!(rect.intersects_rect(Rect::new([0.0, 0.5], [0.5, 1.0])));
assert!(!rect.intersects_rect(Rect::new([1.1, 1.1], [1.0, 1.0])));
assert!(!rect.intersects_rect(Rect::new([-0.1, -0.1], [0.09, 0.09])));
sourcepub fn contains_rect(&self, rect: Rect<N>) -> bool
pub fn contains_rect(&self, rect: Rect<N>) -> bool
Checks if self
contains other
, in other words, it checks if self
fully contains other
.
Arguments
other
: The other rectangle to check if it is inside self.
returns: bool
Examples
use mathie::Rect;
let rect = Rect::one();
assert!(rect.contains_rect(Rect::new([0.0, 0.0], [1.0, 1.0])));
assert!(rect.contains_rect(Rect::new([0.4, 0.4], [0.2, 0.2])));
assert!(!rect.contains_rect(Rect::new([1.0, 1.0], [1.0, 1.0])));
assert!(!rect.contains_rect(Rect::new([0.0, 0.5], [0.5, 1.0])));
assert!(!rect.contains_rect(Rect::new([1.1, 1.1], [1.0, 1.0])));
assert!(!rect.contains_rect(Rect::new([-0.1, -0.1], [0.09, 0.09])));
sourcepub fn contains_pos(&self, pos: Vec2<N>) -> bool
pub fn contains_pos(&self, pos: Vec2<N>) -> bool
Checks if this position is inside this rectangle
Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert!(rect.contains_pos(Vec2::new(0.5, 0.5)));
assert!(rect.contains_pos(Vec2::new(0.0, 0.0)));
assert!(rect.contains_pos(Vec2::new(1.0, 1.0)));
assert!(rect.contains_pos(Vec2::new(0.0, 1.0)));
assert!(rect.contains_pos(Vec2::new(1.0, 0.0)));
assert!(!rect.contains_pos(Vec2::new(0.0, -0.1)));
assert!(!rect.contains_pos(Vec2::new(-0.1, 0.0)));
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Checks if the rectangle has a negative area
Examples
use mathie::{Rect, Vec2};
assert!(!Rect::new([0.0, 0.0], [1.0, 1.0]).is_negative());
assert!(!Rect::new([0.0, 0.0], [0.0, 0.0]).is_negative());
assert!(Rect::new([0.0, 0.0], [-1.0, -1.0]).is_negative());
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the rectangle area is zero, negative or NaN.
Examples
use mathie::{Rect, Vec2};
assert!(!Rect::new([0.0, 0.0], [1.0, 1.0]).is_empty());
assert!(Rect::new([0.0, 0.0], [0.0, 0.0]).is_empty());
assert!(Rect::new([0.0, 0.0], [-1.0, -1.0]).is_empty());
sourcepub fn shrink(&self, value: Vec2<N>) -> Self
pub fn shrink(&self, value: Vec2<N>) -> Self
Makes the rectangle smaller in the x and y directions keeping its center.
Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert_eq!(rect.shrink(Vec2::one()), Rect::new([0.5, 0.5], [0.0, 0.0]));
assert_eq!(rect.shrink(Vec2::one() / 2.0), Rect::new([0.25, 0.25], [0.5, 0.5]));
sourcepub fn expand(&self, value: Vec2<N>) -> Self
pub fn expand(&self, value: Vec2<N>) -> Self
Makes the rectangle bigger in the x and y directions keeping its center.
Examples
use mathie::{Rect, Vec2};
let rect = Rect::one();
assert_eq!(rect.expand(Vec2::one()), Rect::new([-0.5, -0.5], [2.0, 2.0]));
assert_eq!(rect.expand(Vec2::one() / 2.0), Rect::new([-0.25, -0.25], [1.5, 1.5]));
sourcepub fn bottom_right(self) -> Vec2<N>
pub fn bottom_right(self) -> Vec2<N>
Gets the bottom right corner
sourcepub fn bottom_left(self) -> Vec2<N>
pub fn bottom_left(self) -> Vec2<N>
Gets the bottom left corner
sourcepub fn top_center(self) -> Vec2<N>
pub fn top_center(self) -> Vec2<N>
Gets the coordinates to the top of the rectangle while being centered on the x axis
sourcepub fn bottom_center(self) -> Vec2<N>
pub fn bottom_center(self) -> Vec2<N>
Gets the coordinates to the bottom of the rectangle while being centered on the x axis
sourcepub fn center_left(self) -> Vec2<N>
pub fn center_left(self) -> Vec2<N>
Gets the coordinates to the left of the rectangle while being centered on the y axis
sourcepub fn center_right(self) -> Vec2<N>
pub fn center_right(self) -> Vec2<N>
Gets the coordinates to the right of the rectangle while being centered on the y axis
pub fn min(self) -> Vec2<N>
pub fn max(self) -> Vec2<N>
Trait Implementations
sourceimpl<T: Number> AddAssign<Rect<T>> for Rect<T>
impl<T: Number> AddAssign<Rect<T>> for Rect<T>
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresourceimpl<T: Number> AddAssign<T> for Rect<T>
impl<T: Number> AddAssign<T> for Rect<T>
sourcefn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+=
operation. Read moresourceimpl<T: Number> AddAssign<Vec2<T>> for Rect<T>
impl<T: Number> AddAssign<Vec2<T>> for Rect<T>
sourcefn add_assign(&mut self, rhs: Vec2<T>)
fn add_assign(&mut self, rhs: Vec2<T>)
+=
operation. Read moresourceimpl<T: Number> DivAssign<Rect<T>> for Rect<T>
impl<T: Number> DivAssign<Rect<T>> for Rect<T>
sourcefn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moresourceimpl<T: Number> DivAssign<T> for Rect<T>
impl<T: Number> DivAssign<T> for Rect<T>
sourcefn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/=
operation. Read moresourceimpl<T: Number> DivAssign<Vec2<T>> for Rect<T>
impl<T: Number> DivAssign<Vec2<T>> for Rect<T>
sourcefn div_assign(&mut self, rhs: Vec2<T>)
fn div_assign(&mut self, rhs: Vec2<T>)
/=
operation. Read moresourceimpl<T: Number> MulAssign<Rect<T>> for Rect<T>
impl<T: Number> MulAssign<Rect<T>> for Rect<T>
sourcefn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moresourceimpl<T: Number> MulAssign<T> for Rect<T>
impl<T: Number> MulAssign<T> for Rect<T>
sourcefn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*=
operation. Read moresourceimpl<T: Number> MulAssign<Vec2<T>> for Rect<T>
impl<T: Number> MulAssign<Vec2<T>> for Rect<T>
sourcefn mul_assign(&mut self, rhs: Vec2<T>)
fn mul_assign(&mut self, rhs: Vec2<T>)
*=
operation. Read moresourceimpl<N: Number + Ord> Ord for Rect<N>
impl<N: Number + Ord> Ord for Rect<N>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
sourceimpl<N: Number> PartialOrd<Rect<N>> for Rect<N>
impl<N: Number> PartialOrd<Rect<N>> for Rect<N>
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl<T: Number> RemAssign<Rect<T>> for Rect<T>
impl<T: Number> RemAssign<Rect<T>> for Rect<T>
sourcefn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresourceimpl<T: Number> RemAssign<T> for Rect<T>
impl<T: Number> RemAssign<T> for Rect<T>
sourcefn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%=
operation. Read moresourceimpl<T: Number> RemAssign<Vec2<T>> for Rect<T>
impl<T: Number> RemAssign<Vec2<T>> for Rect<T>
sourcefn rem_assign(&mut self, rhs: Vec2<T>)
fn rem_assign(&mut self, rhs: Vec2<T>)
%=
operation. Read moresourceimpl<T: Number> SubAssign<Rect<T>> for Rect<T>
impl<T: Number> SubAssign<Rect<T>> for Rect<T>
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read moresourceimpl<T: Number> SubAssign<T> for Rect<T>
impl<T: Number> SubAssign<T> for Rect<T>
sourcefn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-=
operation. Read moresourceimpl<T: Number> SubAssign<Vec2<T>> for Rect<T>
impl<T: Number> SubAssign<Vec2<T>> for Rect<T>
sourcefn sub_assign(&mut self, rhs: Vec2<T>)
fn sub_assign(&mut self, rhs: Vec2<T>)
-=
operation. Read more