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) -> Self
pub fn expand_rounded(self) -> Self
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>) -> Self
pub fn inset(self, amount: impl Into<Unit>) -> Self
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) -> bool
pub fn intersects(&self, other: &Self) -> bool
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<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> StructuralPartialEq for Rect<Unit>
Auto Trait Implementations§
impl<Unit> Freeze for Rect<Unit>where
Unit: Freeze,
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
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
.