pub struct Rect<T: Coord = i32> { /* private fields */ }Expand description
Rectangle defined by left, top, right and bottom coordinates.
The left and top coordinates are inclusive. The right and bottom coordinates are exclusive.
Implementations§
Source§impl<T: Coord> Rect<T>
impl<T: Coord> Rect<T>
pub fn new(top_left: Point<T>, bottom_right: Point<T>) -> Rect<T>
pub fn width(&self) -> T
pub fn height(&self) -> T
pub fn top(&self) -> T
pub fn left(&self) -> T
pub fn right(&self) -> T
pub fn bottom(&self) -> T
Sourcepub fn corners(&self) -> [Point<T>; 4]
pub fn corners(&self) -> [Point<T>; 4]
Return the corners of the rect in clockwise order, starting from the top left.
Sourcepub fn bottom_left(&self) -> Point<T>
pub fn bottom_left(&self) -> Point<T>
Return the coordinate of the bottom-left corner of the rect.
Sourcepub fn bottom_right(&self) -> Point<T>
pub fn bottom_right(&self) -> Point<T>
Return the coordinate of the bottom-right corner of the rect.
Sourcepub fn right_edge(&self) -> Line<T>
pub fn right_edge(&self) -> Line<T>
Return the line segment of the right edge of the rect.
Sourcepub fn bottom_edge(&self) -> Line<T>
pub fn bottom_edge(&self) -> Line<T>
Return the line segment of the bottom edge of the rect.
Sourcepub fn from_hw(height: T, width: T) -> Rect<T>
pub fn from_hw(height: T, width: T) -> Rect<T>
Return a rect with top-left corner at 0, 0 and the given height/width.
Sourcepub fn from_tlbr(top: T, left: T, bottom: T, right: T) -> Rect<T>
pub fn from_tlbr(top: T, left: T, bottom: T, right: T) -> Rect<T>
Return a rect with the given top, left, bottom and right coordinates.
Sourcepub fn from_tlhw(top: T, left: T, height: T, width: T) -> Rect<T>
pub fn from_tlhw(top: T, left: T, height: T, width: T) -> Rect<T>
Return a rect with the given top, left, height and width.
Sourcepub fn contains_point(&self, other: Point<T>) -> bool
pub fn contains_point(&self, other: Point<T>) -> bool
Return true if other lies on the boundary or interior of this rect.
Sourcepub fn adjust_tlbr(&self, top: T, left: T, bottom: T, right: T) -> Rect<T>
pub fn adjust_tlbr(&self, top: T, left: T, bottom: T, right: T) -> Rect<T>
Return a new Rect with each coordinate adjusted by an offset.
Sourcepub fn intersects(&self, other: Rect<T>) -> bool
pub fn intersects(&self, other: Rect<T>) -> bool
Return true if the intersection of this rect and other is non-empty.
Sourcepub fn union(&self, other: Rect<T>) -> Rect<T>
pub fn union(&self, other: Rect<T>) -> Rect<T>
Return the smallest rect that contains both this rect and other.
Sourcepub fn intersection(&self, other: Rect<T>) -> Rect<T>
pub fn intersection(&self, other: Rect<T>) -> Rect<T>
Return the largest rect that is contained within this rect and other.
Sourcepub fn contains(&self, other: Rect<T>) -> bool
pub fn contains(&self, other: Rect<T>) -> bool
Return true if other lies entirely within this rect.
Sourcepub fn clamp(&self, rect: Rect<T>) -> Rect<T>
pub fn clamp(&self, rect: Rect<T>) -> Rect<T>
Return a new with each side adjusted so that the result lies inside
rect.
pub fn to_polygon(&self) -> Polygon<T, [Point<T>; 4]>
Trait Implementations§
Source§impl<T: Coord> BoundingRect for Rect<T>
impl<T: Coord> BoundingRect for Rect<T>
impl<T: Copy + Coord> Copy for Rect<T>
impl<T: Eq + Coord> Eq for Rect<T>
impl<T: Coord> StructuralPartialEq for Rect<T>
Auto Trait Implementations§
impl<T> Freeze for Rect<T>where
T: Freeze,
impl<T> RefUnwindSafe for Rect<T>where
T: RefUnwindSafe,
impl<T> Send for Rect<T>where
T: Send,
impl<T> Sync for Rect<T>where
T: Sync,
impl<T> Unpin for Rect<T>where
T: Unpin,
impl<T> UnwindSafe for Rect<T>where
T: 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> 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>
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>
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 more