pub struct Rect<N = f64> { /* private fields */ }Expand description
Rectangle in 2d cartesian coordinate space.
Implementations§
Source§impl<N> Rect<N>
impl<N> Rect<N>
Sourcepub fn half_width(&self) -> N
pub fn half_width(&self) -> N
Half of the width of the rectangle. Guaranteed to be non-negative.
Sourcepub fn half_height(&self) -> N
pub fn half_height(&self) -> N
Half of the height of the rectangle. Guaranteed to be non-negative.
Sourcepub fn into_contour(self) -> ClosedContour<Point2<N>>
pub fn into_contour(self) -> ClosedContour<Point2<N>>
Converts the rectangle into a closed contour of points.
Sourcepub fn shrink(&self, amount: N) -> Self
pub fn shrink(&self, amount: N) -> Self
Moves the boundaries of the rectangle by amount inside (outside, if the amount is negative). If the
width or height of the resulting rectangle are negative, they are set to 0.
Sourcepub fn shift(&self, dx: N, dy: N) -> Self
pub fn shift(&self, dx: N, dy: N) -> Self
Adds the given amount to the coordinates of the rectangle.
Sourcepub fn merge(&self, other: Self) -> Self
pub fn merge(&self, other: Self) -> Self
Creates a new rectangle with the boundaries of this and other one.
Sourcepub fn from_point(p: &impl CartesianPoint2d<Num = N>) -> Self
pub fn from_point(p: &impl CartesianPoint2d<Num = N>) -> Self
Creates a zero-area rectangle from the point.
Sourcepub fn from_points<'a, P: CartesianPoint2d<Num = N> + 'a>(
points: impl IntoIterator<Item = P>,
) -> Option<Self>
pub fn from_points<'a, P: CartesianPoint2d<Num = N> + 'a>( points: impl IntoIterator<Item = P>, ) -> Option<Self>
Returns a minimum rectangle that contains all the points in the iterator.
Returns None if the iterator is empty.
Sourcepub fn contains(&self, point: &impl CartesianPoint2d<Num = N>) -> bool
pub fn contains(&self, point: &impl CartesianPoint2d<Num = N>) -> bool
Returns true if the point is inside (or on a side) of the rectagle.
Sourcepub fn magnify(&self, factor: N) -> Self
pub fn magnify(&self, factor: N) -> Self
Changes the width and height of the rectangle by the factor of factor, keeping the center of the rectangle
at the same place.
Sourcepub fn limit(&self, other: Self) -> Self
pub fn limit(&self, other: Self) -> Self
Returns a new rectangle, boundaries of which are inside of boundaries of this and the other rectangles.
Sourcepub fn into_quadrangle(self) -> [Point2<N>; 4]
pub fn into_quadrangle(self) -> [Point2<N>; 4]
Returns a set of 4 points - corners of the rectangle.
The order of points is:
- Left bottom
- Left top
- Right top
- Right bottom
Sourcepub fn intersects(&self, other: Rect<N>) -> bool
pub fn intersects(&self, other: Rect<N>) -> bool
Returns true if two rectangle have at least one common point.
Trait Implementations§
Source§impl<'de, N> Deserialize<'de> for Rect<N>where
N: Deserialize<'de>,
impl<'de, N> Deserialize<'de> for Rect<N>where
N: Deserialize<'de>,
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<N: Num + Copy + PartialOrd + Scalar + FromPrimitive> FromIterator<Rect<N>> for Option<Rect<N>>
impl<N: Num + Copy + PartialOrd + Scalar + FromPrimitive> FromIterator<Rect<N>> for Option<Rect<N>>
Source§impl<N: PartialOrd> PartialOrd for Rect<N>
impl<N: PartialOrd> PartialOrd for Rect<N>
impl<N: Copy> Copy for Rect<N>
impl<N> StructuralPartialEq for Rect<N>
Auto Trait Implementations§
impl<N> Freeze for Rect<N>where
N: Freeze,
impl<N> RefUnwindSafe for Rect<N>where
N: RefUnwindSafe,
impl<N> Send for Rect<N>where
N: Send,
impl<N> Sync for Rect<N>where
N: Sync,
impl<N> Unpin for Rect<N>where
N: Unpin,
impl<N> UnwindSafe for Rect<N>where
N: 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§impl<T> CoordinateMetadata for Twhere
T: ?Sized,
impl<T> CoordinateMetadata for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.