pub struct TypedRect<T, U = UnknownUnit> {
pub origin: TypedPoint2D<T, U>,
pub size: TypedSize2D<T, U>,
}Expand description
A 2d Rectangle optionally tagged with a unit.
Fields§
§origin: TypedPoint2D<T, U>§size: TypedSize2D<T, U>Implementations§
source§impl<T, U> TypedRect<T, U>
impl<T, U> TypedRect<T, U>
sourcepub fn new(
origin: TypedPoint2D<T, U>,
size: TypedSize2D<T, U>,
) -> TypedRect<T, U>
pub fn new( origin: TypedPoint2D<T, U>, size: TypedSize2D<T, U>, ) -> TypedRect<T, U>
Constructor.
source§impl<T, U> TypedRect<T, U>
impl<T, U> TypedRect<T, U>
pub fn intersects(&self, other: &TypedRect<T, U>) -> bool
pub fn max_x(&self) -> T
pub fn min_x(&self) -> T
pub fn max_y(&self) -> T
pub fn min_y(&self) -> T
pub fn max_x_typed(&self) -> Length<T, U>
pub fn min_x_typed(&self) -> Length<T, U>
pub fn max_y_typed(&self) -> Length<T, U>
pub fn min_y_typed(&self) -> Length<T, U>
pub fn intersection(&self, other: &TypedRect<T, U>) -> Option<TypedRect<T, U>>
sourcepub fn translate(&self, other: &TypedPoint2D<T, U>) -> TypedRect<T, U>
pub fn translate(&self, other: &TypedPoint2D<T, U>) -> TypedRect<T, U>
Translates the rect by a vector.
sourcepub fn contains(&self, other: &TypedPoint2D<T, U>) -> bool
pub fn contains(&self, other: &TypedPoint2D<T, U>) -> bool
Returns true if this rectangle contains the point. Points are considered in the rectangle if they are on the left or top edge, but outside if they are on the right or bottom edge.
sourcepub fn contains_rect(&self, rect: &TypedRect<T, U>) -> bool
pub fn contains_rect(&self, rect: &TypedRect<T, U>) -> bool
Returns true if this rectangle contains the interior of rect. Always returns true if rect is empty, and always returns false if rect is nonempty but this rectangle is empty.
pub fn inflate(&self, width: T, height: T) -> TypedRect<T, U>
pub fn inflate_typed( &self, width: Length<T, U>, height: Length<T, U>, ) -> TypedRect<T, U>
pub fn top_right(&self) -> TypedPoint2D<T, U>
pub fn bottom_left(&self) -> TypedPoint2D<T, U>
pub fn bottom_right(&self) -> TypedPoint2D<T, U>
pub fn translate_by_size(&self, size: &TypedSize2D<T, U>) -> TypedRect<T, U>
source§impl<T: Copy, Unit> TypedRect<T, Unit>
impl<T: Copy, Unit> TypedRect<T, Unit>
sourcepub fn to_untyped(&self) -> Rect<T>
pub fn to_untyped(&self) -> Rect<T>
Drop the units, preserving only the numeric value.
sourcepub fn from_untyped(r: &Rect<T>) -> TypedRect<T, Unit>
pub fn from_untyped(r: &Rect<T>) -> TypedRect<T, Unit>
Tag a unitless value with units.
source§impl<T0: NumCast + Copy, Unit> TypedRect<T0, Unit>
impl<T0: NumCast + Copy, Unit> TypedRect<T0, Unit>
sourcepub fn cast<T1: NumCast + Copy>(&self) -> Option<TypedRect<T1, Unit>>
pub fn cast<T1: NumCast + Copy>(&self) -> Option<TypedRect<T1, Unit>>
Cast from one numeric representation to another, preserving the units.
When casting from floating point to integer coordinates, the decimals are truncated as one would expect from a simple cast, but this behavior does not always make sense geometrically. Consider using round(), round_in or round_out() before casting.
source§impl<T: Floor + Ceil + Round + Add<T, Output = T> + Sub<T, Output = T>, U> TypedRect<T, U>
impl<T: Floor + Ceil + Round + Add<T, Output = T> + Sub<T, Output = T>, U> TypedRect<T, U>
sourcepub fn round(&self) -> Self
pub fn round(&self) -> Self
Return a rectangle with edges rounded to integer coordinates, such that the returned rectangle has the same set of pixel centers as the original one. Edges at offset 0.5 round up. Suitable for most places where integral device coordinates are needed, but note that any translation should be applied first to avoid pixel rounding errors. Note that this is not rounding to nearest integer if the values are negative. They are always rounding as floor(n + 0.5).
source§impl<T: NumCast + Copy, Unit> TypedRect<T, Unit>
impl<T: NumCast + Copy, Unit> TypedRect<T, Unit>
sourcepub fn to_uint(&self) -> TypedRect<usize, Unit>
pub fn to_uint(&self) -> TypedRect<usize, Unit>
Cast into an usize vector, truncating decimals if any.
When casting from floating point vectors, it is worth considering whether to round(), round_in() or round_out() before the cast in order to obtain the desired conversion behavior.
Trait Implementations§
source§impl<T: Copy + Deserialize, U> Deserialize for TypedRect<T, U>
impl<T: Copy + Deserialize, U> Deserialize for TypedRect<T, U>
source§fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>where
D: Deserializer,
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error>where
D: Deserializer,
Deserializer.source§impl<T: HeapSizeOf, U> HeapSizeOf for TypedRect<T, U>
impl<T: HeapSizeOf, U> HeapSizeOf for TypedRect<T, U>
source§fn heap_size_of_children(&self) -> usize
fn heap_size_of_children(&self) -> usize
source§impl<T: PartialEq, U> PartialEq for TypedRect<T, U>
impl<T: PartialEq, U> PartialEq for TypedRect<T, U>
impl<T: Copy, U> Copy for TypedRect<T, U>
impl<T: Eq, U> Eq for TypedRect<T, U>
Auto Trait Implementations§
impl<T, U> Freeze for TypedRect<T, U>where
T: Freeze,
impl<T, U> RefUnwindSafe for TypedRect<T, U>where
T: RefUnwindSafe,
U: RefUnwindSafe,
impl<T, U> Send for TypedRect<T, U>
impl<T, U> Sync for TypedRect<T, U>
impl<T, U> Unpin for TypedRect<T, U>
impl<T, U> UnwindSafe for TypedRect<T, U>where
T: UnwindSafe,
U: 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)