#[repr(C)]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>
Sourcepub fn from_size(size: TypedSize2D<T, U>) -> TypedRect<T, U>
pub fn from_size(size: TypedSize2D<T, U>) -> TypedRect<T, U>
Creates a rect of the given size, at offset zero.
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 x_range(&self) -> Range<T>
pub fn y_range(&self) -> Range<T>
pub fn intersection(&self, other: &TypedRect<T, U>) -> Option<TypedRect<T, U>>
Sourcepub fn translate(&self, by: &TypedVector2D<T, U>) -> TypedRect<T, U>
pub fn translate(&self, by: &TypedVector2D<T, U>) -> TypedRect<T, U>
Returns the same rectangle, translated 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 to_box2d(&self) -> TypedBox2D<T, U>
pub fn translate_by_size(&self, size: &TypedSize2D<T, U>) -> TypedRect<T, U>
Sourcepub fn inner_rect(&self, offsets: TypedSideOffsets2D<T, U>) -> TypedRect<T, U>
pub fn inner_rect(&self, offsets: TypedSideOffsets2D<T, U>) -> TypedRect<T, U>
Calculate the size and position of an inner rectangle.
Subtracts the side offsets from all sides. The horizontal and vertical offsets must not be larger than the original side length.
Sourcepub fn outer_rect(&self, offsets: TypedSideOffsets2D<T, U>) -> TypedRect<T, U>
pub fn outer_rect(&self, offsets: TypedSideOffsets2D<T, U>) -> TypedRect<T, U>
Calculate the size and position of an outer rectangle.
Add the offsets to all sides. The expanded rectangle is returned.
Sourcepub fn from_points<I>(points: I) -> TypedRect<T, U>
pub fn from_points<I>(points: I) -> TypedRect<T, U>
Returns the smallest rectangle defined by the top/bottom/left/right-most points provided as parameter.
Note: This function has a behavior that can be surprising because
the right-most and bottom-most points are exactly on the edge
of the rectangle while the contains
function is has exclusive
semantic on these edges. This means that the right-most and bottom-most
points provided to from_points
will count as not contained by the rect.
This behavior may change in the future.
Source§impl<T, Unit> TypedRect<T, Unit>where
T: Copy,
impl<T, Unit> TypedRect<T, Unit>where
T: Copy,
Sourcepub fn to_untyped(&self) -> TypedRect<T>
pub fn to_untyped(&self) -> TypedRect<T>
Drop the units, preserving only the numeric value.
Sourcepub fn from_untyped(r: &TypedRect<T>) -> TypedRect<T, Unit>
pub fn from_untyped(r: &TypedRect<T>) -> TypedRect<T, Unit>
Tag a unitless value with units.
Source§impl<T0, Unit> TypedRect<T0, Unit>
impl<T0, Unit> TypedRect<T0, Unit>
Sourcepub fn cast<T1>(&self) -> TypedRect<T1, Unit>
pub fn cast<T1>(&self) -> 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.
Sourcepub fn try_cast<T1>(&self) -> Option<TypedRect<T1, Unit>>
pub fn try_cast<T1>(&self) -> Option<TypedRect<T1, Unit>>
Fallible 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, U> TypedRect<T, U>
impl<T, U> TypedRect<T, U>
Sourcepub fn round(&self) -> TypedRect<T, U>
pub fn round(&self) -> TypedRect<T, U>
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, Unit> TypedRect<T, Unit>
impl<T, Unit> TypedRect<T, Unit>
Sourcepub fn to_usize(&self) -> TypedRect<usize, Unit>
pub fn to_usize(&self) -> TypedRect<usize, Unit>
Cast into an usize
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.
Sourcepub fn to_u32(&self) -> TypedRect<u32, Unit>
pub fn to_u32(&self) -> TypedRect<u32, Unit>
Cast into an u32
rectangle, truncating decimals if any.
When casting from floating point rectangles, it is worth considering whether
to round()
, round_in()
or round_out()
before the cast in order to
obtain the desired conversion behavior.