#[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> Rect<T>
impl<T> Rect<T>
Sourcepub fn abs_diff_eq(&self, other: &Rect<T>) -> bool
pub fn abs_diff_eq(&self, other: &Rect<T>) -> bool
Returns true if the two values are approximately equal according to the absolute difference between their components.
Source§impl<T> Rect<T>where
T: Copy + RelativeEq<Epsilon = T>,
impl<T> Rect<T>where
T: Copy + RelativeEq<Epsilon = T>,
Sourcepub fn relative_eq(&self, other: &Rect<T>) -> bool
pub fn relative_eq(&self, other: &Rect<T>) -> 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> Rect<T>where
T: Num,
impl<T> Rect<T>where
T: Num,
Sourcepub const fn sized(size: Vec2<T>) -> Rect<T>
pub const fn sized(size: Vec2<T>) -> Rect<T>
A rectangle at (0, 0) with the provided width and height.
Sourcepub const fn pos_size(pos: Vec2<T>, size: Vec2<T>) -> Rect<T>
pub const fn pos_size(pos: Vec2<T>, size: Vec2<T>) -> Rect<T>
A rectangle at pos with the size.
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 inflate(self, amount: impl Into<Vec2<T>>) -> Rect<T>
pub fn inflate(self, amount: impl Into<Vec2<T>>) -> Rect<T>
Inflate the rectangle by the amount.
Sourcepub fn contains_rect(&self, r: &Rect<T>) -> bool
pub fn contains_rect(&self, r: &Rect<T>) -> bool
If this rectangle contains the other.
Sourcepub fn overlap(&self, r: &Rect<T>) -> Option<Rect<T>>
pub fn overlap(&self, r: &Rect<T>) -> Option<Rect<T>>
If this rectangle overlaps the other, returns a rectangle representing the overlapping region.
Sourcepub fn conflate(&self, r: &Rect<T>) -> Rect<T>
pub fn conflate(&self, r: &Rect<T>) -> Rect<T>
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: &Rect<T>) -> Rect<T>
pub fn clamp_inside(&self, outer: &Rect<T>) -> Rect<T>
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.
Trait Implementations§
Source§impl<T> AbsDiffEq for Rect<T>
impl<T> AbsDiffEq for Rect<T>
Source§fn default_epsilon() -> <Rect<T> as AbsDiffEq>::Epsilon
fn default_epsilon() -> <Rect<T> as AbsDiffEq>::Epsilon
Source§fn abs_diff_eq(
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq>::Epsilon,
) -> bool
fn abs_diff_eq( &self, other: &Rect<T>, epsilon: <Rect<T> as AbsDiffEq>::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> AddAssign<&Vec2<T>> for Rect<T>
impl<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<Vec2<T>> for Rect<T>where
T: AddAssign,
impl<T> AddAssign<Vec2<T>> for Rect<T>where
T: AddAssign,
Source§fn add_assign(&mut self, rhs: Vec2<T>)
fn add_assign(&mut self, rhs: Vec2<T>)
+= operation. Read moreimpl<T> Copy for Rect<T>where
T: Copy,
Source§impl<'de, T> Deserialize<'de> for Rect<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Rect<T>where
T: Deserialize<'de>,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Rect<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Rect<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> DivAssign<T> for Rect<T>where
T: Num,
impl<T> DivAssign<T> for Rect<T>where
T: Num,
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
/= operation. Read moreimpl<T> Eq for Rect<T>where
T: Eq,
Source§impl<T> From<(T, T, T, T)> for Rect<T>
impl<T> From<(T, T, T, T)> for Rect<T>
Source§fn from(_: (T, T, T, T)) -> Rect<T>
fn from(_: (T, T, T, T)) -> Rect<T>
Source§impl<T> Interp for Rect<T>
impl<T> Interp for Rect<T>
Source§fn lerp(self, target: Rect<T>, t: <Rect<T> as Interp>::Factor) -> Rect<T>
fn lerp(self, target: Rect<T>, t: <Rect<T> as Interp>::Factor) -> Rect<T>
Source§fn quad_bezier(
self,
control: Rect<T>,
target: Rect<T>,
t: <Rect<T> as Interp>::Factor,
) -> Rect<T>
fn quad_bezier( self, control: Rect<T>, target: Rect<T>, t: <Rect<T> as Interp>::Factor, ) -> Rect<T>
Source§fn cubic_bezier(
self,
control1: Rect<T>,
control2: Rect<T>,
target: Rect<T>,
t: <Rect<T> as Interp>::Factor,
) -> Rect<T>
fn cubic_bezier( self, control1: Rect<T>, control2: Rect<T>, target: Rect<T>, t: <Rect<T> as Interp>::Factor, ) -> Rect<T>
Source§fn hermite(
self,
tangent1: <Rect<T> as Interp>::Factor,
target: Rect<T>,
tangent2: <Rect<T> as Interp>::Factor,
t: <Rect<T> as Interp>::Factor,
) -> Rect<T>
fn hermite( self, tangent1: <Rect<T> as Interp>::Factor, target: Rect<T>, tangent2: <Rect<T> as Interp>::Factor, t: <Rect<T> as Interp>::Factor, ) -> Rect<T>
Source§impl<T> MulAssign<T> for Rect<T>where
T: Num,
impl<T> MulAssign<T> for Rect<T>where
T: Num,
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
*= operation. Read moreSource§impl<T> Numeric for Rect<T>
impl<T> 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 for Rect<T>where
T: Ord,
impl<T> Ord for Rect<T>where
T: Ord,
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T> PartialOrd for Rect<T>where
T: PartialOrd,
impl<T> PartialOrd for Rect<T>where
T: PartialOrd,
impl<T> Pod for Rect<T>where
T: Pod,
Source§impl<T> Polygonal<T> for Rect<T>where
T: Float,
impl<T> Polygonal<T> for Rect<T>where
T: Float,
Source§fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
fn nearest_vertex(&self, source: Vec2<T>) -> Vec2<T>
Source§fn all_edges<F>(&self, cond: F) -> bool
fn all_edges<F>(&self, cond: F) -> bool
Source§fn all_normals<F>(&self, cond: F) -> bool
fn all_normals<F>(&self, cond: F) -> bool
Source§fn visit_normals<F>(&self, plot: F)
fn visit_normals<F>(&self, plot: F)
Source§fn visit_edges<F>(&self, plot: F)
fn visit_edges<F>(&self, plot: F)
Source§impl<T> RelativeEq for Rect<T>
impl<T> RelativeEq for Rect<T>
Source§fn default_max_relative() -> <Rect<T> as AbsDiffEq>::Epsilon
fn default_max_relative() -> <Rect<T> as AbsDiffEq>::Epsilon
Source§fn relative_eq(
&self,
other: &Rect<T>,
epsilon: <Rect<T> as AbsDiffEq>::Epsilon,
max_relative: <Rect<T> as AbsDiffEq>::Epsilon,
) -> bool
fn relative_eq( &self, other: &Rect<T>, epsilon: <Rect<T> as AbsDiffEq>::Epsilon, max_relative: <Rect<T> as AbsDiffEq>::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> RemAssign<T> for Rect<T>where
T: Num,
impl<T> RemAssign<T> for Rect<T>where
T: Num,
Source§fn rem_assign(&mut self, rhs: T)
fn rem_assign(&mut self, rhs: T)
%= operation. Read moreSource§impl<T> Serialize for Rect<T>where
T: Serialize,
impl<T> Serialize for Rect<T>where
T: Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> Shape<T> for Rect<T>where
T: Float,
impl<T> Shape<T> for Rect<T>where
T: Float,
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>(&self, poly: &P) -> boolwhere
P: Polygonal<T>,
fn overlaps_poly<P>(&self, poly: &P) -> boolwhere
P: Polygonal<T>,
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> SmoothInterp for Rect<T>where
T: Float + SmoothInterp<Factor = T>,
impl<T> SmoothInterp for Rect<T>where
T: Float + SmoothInterp<Factor = T>,
impl<T> StructuralPartialEq for Rect<T>where
T: PartialEq,
Source§impl<T> SubAssign<&Vec2<T>> for Rect<T>
impl<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<Vec2<T>> for Rect<T>where
T: SubAssign,
impl<T> SubAssign<Vec2<T>> for Rect<T>where
T: SubAssign,
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>
Source§fn default_max_ulps() -> u32
fn default_max_ulps() -> u32
Auto Trait Implementations§
impl<T> Forget for Rect<T>
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> UnsafeUnpin for Rect<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Rect<T>where
T: UnwindSafe,
Blanket Implementations§
impl<T> AnyBitPattern for Twhere
T: Pod,
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.Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> NoUninit for Twhere
T: Pod,
impl<T, Rhs, Output> NumOps<Rhs, Output> for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more