pub struct Rect<Unit> {
pub origin: Point<Unit>,
pub size: Size<Unit>,
}
Fields§
§origin: Point<Unit>
The origin of the rectangle
size: Size<Unit>
The size of the rectangle.
Implementations§
source§impl<Unit> Rect<Unit>
impl<Unit> Rect<Unit>
sourcepub fn from_extents(p1: Point<Unit>, p2: Point<Unit>) -> Selfwhere
Unit: Unit,
pub fn from_extents(p1: Point<Unit>, p2: Point<Unit>) -> Selfwhere Unit: Unit,
Returns a new rectangle using the given points to form the top-left and bottom-right of the rectangle.
The order of the parameters does not matter. The minimum values will form the top-left and the maximum values will form the bottom-right.
sourcepub fn expand_rounded(self) -> Selfwhere
Unit: Round + Unit,
pub fn expand_rounded(self) -> Selfwhere Unit: Round + Unit,
Expands this rect to the nearest whole number.
This function will never return a smaller rectangle.
sourcepub fn map<NewUnit>(self, map: impl FnMut(Unit) -> NewUnit) -> Rect<NewUnit>
pub fn map<NewUnit>(self, map: impl FnMut(Unit) -> NewUnit) -> Rect<NewUnit>
Maps each component to map
and returns a new value with the mapped
components.
sourcepub fn inset(self, amount: impl Into<Unit>) -> Selfwhere
Unit: Add<Unit, Output = Unit> + AddAssign<Unit> + SubAssign<Unit> + Copy,
pub fn inset(self, amount: impl Into<Unit>) -> Selfwhere Unit: Add<Unit, Output = Unit> + AddAssign<Unit> + SubAssign<Unit> + Copy,
Returns a rectangle that has been inset by amount
on all sides.
sourcepub fn cast<NewUnit>(self) -> Rect<NewUnit>where
NewUnit: From<Unit>,
pub fn cast<NewUnit>(self) -> Rect<NewUnit>where NewUnit: From<Unit>,
Converts the contents of this point to NewUnit
using From
.
sourcepub fn try_cast<NewUnit>(self) -> Result<Rect<NewUnit>, NewUnit::Error>where
NewUnit: TryFrom<Unit>,
pub fn try_cast<NewUnit>(self) -> Result<Rect<NewUnit>, NewUnit::Error>where NewUnit: TryFrom<Unit>,
sourcepub fn contains(&self, point: Point<Unit>) -> boolwhere
Unit: Unit,
pub fn contains(&self, point: Point<Unit>) -> boolwhere Unit: Unit,
Returns true if this rect contains point
.
sourcepub fn intersects(&self, other: &Self) -> boolwhere
Unit: Add<Output = Unit> + Ord + Copy,
pub fn intersects(&self, other: &Self) -> boolwhere Unit: Add<Output = Unit> + Ord + Copy,
Returns true if the areas of self
and other
overlap.
This function does not return true if the edges touch but do not overlap.
use figures::{Point, Rect, Size};
let a: Rect<i32> = Rect::new(Point::new(1, 1), Size::new(2, 2));
let b = Rect::new(Point::new(2, 2), Size::new(1, 1));
assert!(a.intersects(&b));
let c = Rect::new(Point::new(3, 1), Size::new(1, 1));
assert!(!a.intersects(&c));
sourcepub fn intersection(&self, other: &Self) -> Option<Rect<Unit>>where
Unit: Unit,
pub fn intersection(&self, other: &Self) -> Option<Rect<Unit>>where Unit: Unit,
Returns the overlapping rectangle of self
and other
. If the
rectangles do not overlap, None will be returned.
use figures::{Point, Rect, Size};
let a: Rect<i32> = Rect::new(Point::new(1, 1), Size::new(3, 3));
let b = Rect::new(Point::new(2, 2), Size::new(3, 3));
assert_eq!(
a.intersection(&b),
Some(Rect::new(Point::new(2, 2), Size::new(2, 2)))
);
let c = Rect::new(Point::new(4, 1), Size::new(1, 1));
assert_eq!(a.intersection(&c), None);
Trait Implementations§
source§impl<'de, Unit> Deserialize<'de> for Rect<Unit>where
Unit: Deserialize<'de>,
impl<'de, Unit> Deserialize<'de> for Rect<Unit>where Unit: 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<Unit> IntoSigned for Rect<Unit>where
Unit: IntoSigned,
impl<Unit> IntoSigned for Rect<Unit>where Unit: IntoSigned,
§type Signed = Rect<<Unit as IntoSigned>::Signed>
type Signed = Rect<<Unit as IntoSigned>::Signed>
source§fn into_signed(self) -> Self::Signed
fn into_signed(self) -> Self::Signed
i32
are converted to i32::MAX
.source§impl<Unit> IntoUnsigned for Rect<Unit>where
Unit: IntoUnsigned,
impl<Unit> IntoUnsigned for Rect<Unit>where Unit: IntoUnsigned,
§type Unsigned = Rect<<Unit as IntoUnsigned>::Unsigned>
type Unsigned = Rect<<Unit as IntoUnsigned>::Unsigned>
source§fn into_unsigned(self) -> Self::Unsigned
fn into_unsigned(self) -> Self::Unsigned
source§impl<Unit: PartialEq> PartialEq for Rect<Unit>
impl<Unit: PartialEq> PartialEq for Rect<Unit>
impl<Unit: Copy> Copy for Rect<Unit>
impl<Unit: Eq> Eq for Rect<Unit>
impl<Unit> StructuralEq for Rect<Unit>
impl<Unit> StructuralPartialEq for Rect<Unit>
Auto Trait Implementations§
impl<Unit> RefUnwindSafe for Rect<Unit>where Unit: RefUnwindSafe,
impl<Unit> Send for Rect<Unit>where Unit: Send,
impl<Unit> Sync for Rect<Unit>where Unit: Sync,
impl<Unit> Unpin for Rect<Unit>where Unit: Unpin,
impl<Unit> UnwindSafe for Rect<Unit>where Unit: 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
§impl<A> Cast for A
impl<A> Cast for A
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<Unit> IntoComponents<Unit> for Unitwhere
Unit: Copy,
impl<Unit> IntoComponents<Unit> for Unitwhere Unit: Copy,
source§fn into_components(self) -> (Unit, Unit)
fn into_components(self) -> (Unit, Unit)
source§fn to_vec<Type>(self) -> Typewhere
Type: FromComponents<Unit>,
fn to_vec<Type>(self) -> Typewhere Type: FromComponents<Unit>,
FromComponents
and
IntoComponents
.