#[repr(C)]pub struct Rect<T> {
pub x: T,
pub y: T,
pub w: T,
pub h: T,
}Expand description
A 2D axis-aligned rectangle.
Most of the methods for this struct assume that the rectangle
has a positive width and height, so rectangles where T is
signed may yield incorrect values for negative-sized instances.
Fields§
§x: T§y: T§w: T§h: TImplementations§
Source§impl<T: Copy + AbsDiffEq<Epsilon = T>> Rect<T>
impl<T: Copy + AbsDiffEq<Epsilon = T>> Rect<T>
Sourcepub fn abs_diff_eq(&self, other: &Self) -> bool
pub fn abs_diff_eq(&self, other: &Self) -> bool
Returns true if the two values are approximately equal according to the absolute difference between their components.
Source§impl<T: Copy + RelativeEq<Epsilon = T>> Rect<T>
impl<T: Copy + RelativeEq<Epsilon = T>> Rect<T>
Sourcepub fn relative_eq(&self, other: &Self) -> bool
pub fn relative_eq(&self, other: &Self) -> bool
Returns true if the two values are approximately equal according to the absolute difference between their components, as well as relative-based comparisons.
Source§impl<T: Num> Rect<T>
impl<T: Num> Rect<T>
Sourcepub const fn sized(size: Vec2<T>) -> Self
pub const fn sized(size: Vec2<T>) -> Self
A rectangle at (0, 0) with the provided width and height.
Sourcepub fn bottom_right(&self) -> Vec2<T>
pub fn bottom_right(&self) -> Vec2<T>
Bottom-right point of the rectangle.
Sourcepub fn bottom_left(&self) -> Vec2<T>
pub fn bottom_left(&self) -> Vec2<T>
Bottom-left point of the rectangle.
Sourcepub fn top_center(&self) -> Vec2<T>
pub fn top_center(&self) -> Vec2<T>
Center point along the rectangle’s top edge.
Sourcepub fn bottom_center(&self) -> Vec2<T>
pub fn bottom_center(&self) -> Vec2<T>
Center point along the rectangle’s bottom edge.
Sourcepub fn right_center(&self) -> Vec2<T>
pub fn right_center(&self) -> Vec2<T>
Center point along the rectangle’s right edge.
Sourcepub fn left_center(&self) -> Vec2<T>
pub fn left_center(&self) -> Vec2<T>
Center point along the rectangle’s left edge.
Sourcepub fn right_edge(&self) -> Line<T>
pub fn right_edge(&self) -> Line<T>
Right edge segment of the rectangle.
Sourcepub fn bottom_edge(&self) -> Line<T>
pub fn bottom_edge(&self) -> Line<T>
Bottom edge segment of the rectangle.
Sourcepub fn contains_rect(&self, r: &Self) -> bool
pub fn contains_rect(&self, r: &Self) -> bool
If this rectangle contains the other.
Sourcepub fn overlap(&self, r: &Self) -> Option<Self>
pub fn overlap(&self, r: &Self) -> Option<Self>
If this rectangle overlaps the other, returns a rectangle representing the overlapping region.
Sourcepub fn conflate(&self, r: &Self) -> Self
pub fn conflate(&self, r: &Self) -> Self
Return a rectangle that minimally encapsulates this rectangle and the other. This is useful if you have a lot of rectangles (or bounds) and want to find the minimal sum boundary that contains them all.
Sourcepub fn clamp_inside(&self, outer: &Self) -> Self
pub fn clamp_inside(&self, outer: &Self) -> Self
Return a rectangle that is this rectangle clamped inside of the provided outer rectangle. If this rectangle is larger than the outer by either dimension, it will be shrunk to fit.
Source§impl<T: Signed> Rect<T>
impl<T: Signed> Rect<T>
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
If the rectangle has a non-negative size.
Trait Implementations§
Source§impl<T> AbsDiffEq for Rect<T>
impl<T> AbsDiffEq for Rect<T>
Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl<T: Copy + AddAssign<T>> AddAssign<&Vec2<T>> for Rect<T>
impl<T: Copy + AddAssign<T>> AddAssign<&Vec2<T>> for Rect<T>
Source§fn add_assign(&mut self, rhs: &Vec2<T>)
fn add_assign(&mut self, rhs: &Vec2<T>)
+= operation. Read moreSource§impl<T: AddAssign<T>> AddAssign<Vec2<T>> for Rect<T>
impl<T: AddAssign<T>> AddAssign<Vec2<T>> for Rect<T>
Source§fn add_assign(&mut self, rhs: Vec2<T>)
fn add_assign(&mut self, rhs: Vec2<T>)
+= operation. Read moreSource§impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rect<T>
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Rect<T>
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>,
Source§impl<T: Num> DivAssign<T> for Rect<T>
impl<T: Num> DivAssign<T> for Rect<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreSource§impl<T> From<(T, T, T, T)> for Rect<T>
impl<T> From<(T, T, T, T)> for Rect<T>
Source§fn from((x, y, w, h): (T, T, T, T)) -> Self
fn from((x, y, w, h): (T, T, T, T)) -> Self
Source§impl<T> From<Rect<T>> for (T, T, T, T)
impl<T> From<Rect<T>> for (T, T, T, T)
Source§fn from(_: Rect<T>) -> (T, T, T, T)
fn from(_: Rect<T>) -> (T, T, T, T)
Source§impl<T: Float + Interp<Factor = T>> Interp for Rect<T>
impl<T: Float + Interp<Factor = T>> Interp for Rect<T>
Source§fn quad_bezier(self, control: Self, target: Self, t: Self::Factor) -> Self
fn quad_bezier(self, control: Self, target: Self, t: Self::Factor) -> Self
Source§fn cubic_bezier(
self,
control1: Self,
control2: Self,
target: Self,
t: Self::Factor,
) -> Self
fn cubic_bezier( self, control1: Self, control2: Self, target: Self, t: Self::Factor, ) -> Self
Source§fn hermite(
self,
tangent1: Self::Factor,
target: Self,
tangent2: Self::Factor,
t: Self::Factor,
) -> Self
fn hermite( self, tangent1: Self::Factor, target: Self, tangent2: Self::Factor, t: Self::Factor, ) -> Self
Source§fn catmull_rom(
self,
control1: Self,
control2: Self,
target: Self,
t: Self::Factor,
) -> Self
fn catmull_rom( self, control1: Self, control2: Self, target: Self, t: Self::Factor, ) -> Self
Source§fn smooth_step(self, target: Self, t: Self::Factor) -> Self
fn smooth_step(self, target: Self, t: Self::Factor) -> Self
Source§impl<T: Num> MulAssign<T> for Rect<T>
impl<T: Num> MulAssign<T> for Rect<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T: Numeric<AsU8 = u8, AsU16 = u16, AsU32 = u32, AsU64 = u64, AsU128 = u128, AsUSize = usize, AsI8 = i8, AsI16 = i16, AsI32 = i32, AsI64 = i64, AsI128 = i128, AsISize = isize, AsF32 = f32, AsF64 = f64>> Numeric for Rect<T>
impl<T: Numeric<AsU8 = u8, AsU16 = u16, AsU32 = u32, AsU64 = u64, AsU128 = u128, AsUSize = usize, AsI8 = i8, AsI16 = i16, AsI32 = i32, AsI64 = i64, AsI128 = i128, AsISize = isize, AsF32 = f32, AsF64 = f64>> Numeric for Rect<T>
type AsU8 = Rect<u8>
type AsU16 = Rect<u16>
type AsU32 = Rect<u32>
type AsU64 = Rect<u64>
type AsU128 = Rect<u128>
type AsUSize = Rect<usize>
type AsI8 = Rect<i8>
type AsI16 = Rect<i16>
type AsI32 = Rect<i32>
type AsI64 = Rect<i64>
type AsI128 = Rect<i128>
type AsISize = Rect<isize>
type AsF32 = Rect<f32>
type AsF64 = Rect<f64>
fn to_u8(self) -> Rect<u8>
fn to_u16(self) -> Rect<u16>
fn to_u32(self) -> Rect<u32>
fn to_u64(self) -> Rect<u64>
fn to_u128(self) -> Rect<u128>
fn to_usize(self) -> Rect<usize>
fn to_i8(self) -> Rect<i8>
fn to_i16(self) -> Rect<i16>
fn to_i32(self) -> Rect<i32>
fn to_i64(self) -> Rect<i64>
fn to_i128(self) -> Rect<i128>
fn to_isize(self) -> Rect<isize>
fn to_f32(self) -> Rect<f32>
fn to_f64(self) -> Rect<f64>
Source§impl<T: Ord> Ord for Rect<T>
impl<T: Ord> Ord for Rect<T>
Source§impl<T: PartialOrd> PartialOrd for Rect<T>
impl<T: PartialOrd> PartialOrd for Rect<T>
Source§impl<T: Float> Polygonal<T> for Rect<T>
impl<T: Float> Polygonal<T> for Rect<T>
Source§fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
Source§fn all_edges<F: FnMut(Line<T>) -> bool>(&self, cond: F) -> bool
fn all_edges<F: FnMut(Line<T>) -> bool>(&self, cond: F) -> bool
Source§fn all_normals<F: FnMut(Vec2<T>) -> bool>(&self, cond: F) -> bool
fn all_normals<F: FnMut(Vec2<T>) -> bool>(&self, cond: F) -> bool
Source§fn visit_normals<F: FnMut(Vec2<T>)>(&self, plot: F)
fn visit_normals<F: FnMut(Vec2<T>)>(&self, plot: F)
Source§fn visit_edges<F: FnMut(Line<T>)>(&self, plot: F)
fn visit_edges<F: FnMut(Line<T>)>(&self, plot: F)
Source§impl<T> RelativeEq for Rect<T>
impl<T> RelativeEq for Rect<T>
Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
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
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
RelativeEq::relative_eq.Source§impl<T: Num> RemAssign<T> for Rect<T>
impl<T: Num> RemAssign<T> for Rect<T>
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%= operation. Read moreSource§impl<T: Float> Shape<T> for Rect<T>
impl<T: Float> Shape<T> for Rect<T>
Source§fn project_onto_axis(&self, axis: Vec2<T>) -> Projection<T>
fn project_onto_axis(&self, axis: Vec2<T>) -> Projection<T>
Source§fn project_point(&self, p: Vec2<T>) -> Vec2<T>
fn project_point(&self, p: Vec2<T>) -> Vec2<T>
Source§fn overlaps_rect(&self, rect: &Rect<T>) -> bool
fn overlaps_rect(&self, rect: &Rect<T>) -> bool
Source§fn overlaps_circ(&self, circ: &Circle<T>) -> bool
fn overlaps_circ(&self, circ: &Circle<T>) -> bool
Source§fn overlaps_poly<P: Polygonal<T>>(&self, poly: &P) -> bool
fn overlaps_poly<P: Polygonal<T>>(&self, poly: &P) -> bool
Source§fn extract_from_circ(&self, circ: &Circle<T>) -> Option<Vec2<T>>
fn extract_from_circ(&self, circ: &Circle<T>) -> Option<Vec2<T>>
Source§impl<T: Float + SmoothInterp<Factor = T>> SmoothInterp for Rect<T>
impl<T: Float + SmoothInterp<Factor = T>> SmoothInterp for Rect<T>
Source§impl<T: Copy + SubAssign<T>> SubAssign<&Vec2<T>> for Rect<T>
impl<T: Copy + SubAssign<T>> SubAssign<&Vec2<T>> for Rect<T>
Source§fn sub_assign(&mut self, rhs: &Vec2<T>)
fn sub_assign(&mut self, rhs: &Vec2<T>)
-= operation. Read moreSource§impl<T: SubAssign<T>> SubAssign<Vec2<T>> for Rect<T>
impl<T: SubAssign<T>> SubAssign<Vec2<T>> for Rect<T>
Source§fn sub_assign(&mut self, rhs: Vec2<T>)
fn sub_assign(&mut self, rhs: Vec2<T>)
-= operation. Read moreSource§impl<T> UlpsEq for Rect<T>
impl<T> UlpsEq for Rect<T>
impl<T: Copy> Copy for Rect<T>
impl<T: Eq> Eq for Rect<T>
impl<T: Pod> Pod for Rect<T>
impl<T> StructuralPartialEq for Rect<T>
Auto Trait Implementations§
impl<T> Freeze for Rect<T>where
T: Freeze,
impl<T> RefUnwindSafe for Rect<T>where
T: RefUnwindSafe,
impl<T> Send for Rect<T>where
T: Send,
impl<T> Sync for Rect<T>where
T: Sync,
impl<T> Unpin for Rect<T>where
T: Unpin,
impl<T> UnwindSafe for Rect<T>where
T: UnwindSafe,
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
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.