pub struct Rect { /* private fields */ }
Expand description
A rectangular region of non-zero width and height.
§Examples
use imageproc::rect::Rect;
use imageproc::rect::Region;
// Construct a rectangle with top-left corner at (4, 5), width 6 and height 7.
let rect = Rect::at(4, 5).of_size(6, 7);
// Contains top-left point:
assert_eq!(rect.left(), 4);
assert_eq!(rect.top(), 5);
assert!(rect.contains(rect.left(), rect.top()));
// Contains bottom-right point, at (left + width - 1, top + height - 1):
assert_eq!(rect.right(), 9);
assert_eq!(rect.bottom(), 11);
assert!(rect.contains(rect.right(), rect.bottom()));
Implementations§
Source§impl Rect
impl Rect
Sourcepub fn at(x: i32, y: i32) -> RectPosition
pub fn at(x: i32, y: i32) -> RectPosition
Reduces possibility of confusing coordinates and dimensions when specifying rects.
See the struct-level documentation for examples.
Sourcepub fn top(&self) -> i32
pub fn top(&self) -> i32
Smallest y-coordinate reached by rect.
See the struct-level documentation for examples.
Sourcepub fn left(&self) -> i32
pub fn left(&self) -> i32
Smallest x-coordinate reached by rect.
See the struct-level documentation for examples.
Sourcepub fn bottom(&self) -> i32
pub fn bottom(&self) -> i32
Greatest y-coordinate reached by rect.
See the struct-level documentation for examples.
Sourcepub fn right(&self) -> i32
pub fn right(&self) -> i32
Greatest x-coordinate reached by rect.
See the struct-level documentation for examples.
Sourcepub fn intersect(&self, other: Rect) -> Option<Rect>
pub fn intersect(&self, other: Rect) -> Option<Rect>
Returns the intersection of self and other, or none if they are are disjoint.
§Examples
use imageproc::rect::Rect;
use imageproc::rect::Region;
// Intersecting a rectangle with itself
let r = Rect::at(4, 5).of_size(6, 7);
assert_eq!(r.intersect(r), Some(r));
// Intersecting overlapping but non-equal rectangles
let r = Rect::at(0, 0).of_size(5, 5);
let s = Rect::at(1, 4).of_size(10, 12);
let i = Rect::at(1, 4).of_size(4, 1);
assert_eq!(r.intersect(s), Some(i));
// Intersecting disjoint rectangles
let r = Rect::at(0, 0).of_size(5, 5);
let s = Rect::at(10, 10).of_size(100, 12);
assert_eq!(r.intersect(s), None);
Trait Implementations§
impl Copy for Rect
impl Eq for Rect
impl StructuralPartialEq for Rect
Auto Trait Implementations§
impl Freeze for Rect
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Convert the given value into an approximately equivalent representation.
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
The error type produced by a failed conversion.
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Approximate the subject to a given type with the default scheme.
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
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>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
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
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.