Rect

Struct Rect 

Source
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>

Source

pub fn new(top_left: Point<T>, bottom_right: Point<T>) -> Rect<T>

Source

pub fn width(&self) -> T

Source

pub fn height(&self) -> T

Source

pub fn top(&self) -> T

Source

pub fn left(&self) -> T

Source

pub fn right(&self) -> T

Source

pub fn bottom(&self) -> T

Source

pub fn corners(&self) -> [Point<T>; 4]

Return the corners of the rect in clockwise order, starting from the top left.

Source

pub fn top_left(&self) -> Point<T>

Return the coordinate of the top-left corner of the rect.

Source

pub fn top_right(&self) -> Point<T>

Return the coordinate of the top-right corner of the rect.

Source

pub fn bottom_left(&self) -> Point<T>

Return the coordinate of the bottom-left corner of the rect.

Source

pub fn bottom_right(&self) -> Point<T>

Return the coordinate of the bottom-right corner of the rect.

Source

pub fn left_edge(&self) -> Line<T>

Return the line segment of the left edge of the rect.

Source

pub fn top_edge(&self) -> Line<T>

Return the line segment of the top edge of the rect.

Source

pub fn right_edge(&self) -> Line<T>

Return the line segment of the right edge of the rect.

Source

pub fn bottom_edge(&self) -> Line<T>

Return the line segment of the bottom edge of the rect.

Source

pub fn tlbr(&self) -> [T; 4]

Return the top, left, bottom and right coordinates as an array.

Source

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.

Source

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.

Source

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.

Source

pub fn area(&self) -> T
where T: Mul<Output = T>,

Return the signed area of this rect.

Source

pub fn tlhw(&self) -> [T; 4]

Return the top, left, height and width as an array.

Source

pub fn contains_point(&self, other: Point<T>) -> bool

Return true if other lies on the boundary or interior of this rect.

Source

pub fn is_empty(&self) -> bool

Return true if the width or height of this rect are <= 0.

Source

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.

Source

pub fn intersects(&self, other: Rect<T>) -> bool

Return true if the intersection of this rect and other is non-empty.

Source

pub fn union(&self, other: Rect<T>) -> Rect<T>

Return the smallest rect that contains both this rect and other.

Source

pub fn intersection(&self, other: Rect<T>) -> Rect<T>

Return the largest rect that is contained within this rect and other.

Source

pub fn contains(&self, other: Rect<T>) -> bool

Return true if other lies entirely within this rect.

Source

pub fn clamp(&self, rect: Rect<T>) -> Rect<T>

Return a new with each side adjusted so that the result lies inside rect.

Source

pub fn to_polygon(&self) -> Polygon<T, [Point<T>; 4]>

Source§

impl Rect<i32>

Source

pub fn center(&self) -> Point

Return the center point of the rect.

Source

pub fn iou(&self, other: Rect) -> f32

Return the Intersection over Union ratio for this rect and other.

See https://en.wikipedia.org/wiki/Jaccard_index.

Source

pub fn to_f32(&self) -> RectF

Source§

impl Rect<f32>

Source

pub fn center(&self) -> PointF

Return the center point of the rect.

Source

pub fn iou(&self, other: RectF) -> f32

Return the Intersection over Union ratio for this rect and other.

See https://en.wikipedia.org/wiki/Jaccard_index.

Source

pub fn integral_bounding_rect(&self) -> Rect<i32>

Return the smallest rect with integral coordinates that contains this rect.

Trait Implementations§

Source§

impl<T: Coord> BoundingRect for Rect<T>

Source§

type Coord = T

Coordinate type of bounding rect.
Source§

fn bounding_rect(&self) -> Rect<T>

Return the smallest axis-aligned bounding rect which contains this shape.
Source§

impl<T: Clone + Coord> Clone for Rect<T>

Source§

fn clone(&self) -> Rect<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Coord> Debug for Rect<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq + Coord> PartialEq for Rect<T>

Source§

fn eq(&self, other: &Rect<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy + Coord> Copy for Rect<T>

Source§

impl<T: Eq + Coord> Eq for Rect<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.