Skip to main content

BoundingRect

Struct BoundingRect 

Source
pub struct BoundingRect {
    pub left: i32,
    pub top: i32,
    pub right: i32,
    pub bottom: i32,
}
Expand description

The rectangle that bounds an object

Fields§

§left: i32§top: i32§right: i32§bottom: i32

Implementations§

Source§

impl BoundingRect

Source

pub fn new_x_y_w_h(x: i32, y: i32, w: i32, h: i32) -> Self

Source

pub fn width(self) -> i32

Source

pub fn height(self) -> i32

Source

pub fn is_empty(self) -> bool

Source

pub fn center(self) -> PointI32

Source

pub fn left_top(&self) -> PointI32

Source

pub fn top_left(&self) -> PointI32

Source

pub fn top_right(&self) -> PointI32

Source

pub fn bottom_left(&self) -> PointI32

Source

pub fn right_bottom(&self) -> PointI32

Source

pub fn bottom_right(&self) -> PointI32

Source

pub fn sq_dist(self, other: Self) -> i32

Calculates the squared distance betweeen the center of two BoundingRects.

Source

pub fn aspect_ratio(self) -> f64

Source

pub fn aspect_ratio_doubled(self) -> i32

Source

pub fn add_x_y(&mut self, x: i32, y: i32)

Source

pub fn merge(&mut self, other: Self)

Source

pub fn clear(&mut self)

Source

pub fn hit(self, other: Self) -> bool

Source

pub fn clip(&mut self, other: Self)

Source

pub fn squared(self) -> Self

Source

pub fn translate(&mut self, p: PointI32)

Source

pub fn have_point_on_boundary(&self, p: PointI32, tolerance: usize) -> bool

Tolerance means: 1. Extend each boundary on both sides by tolerance units along its direction. 2. true is returned iff p lies on either one of the extended boundaries.

A point p lying on boundary “strictly” means this function returns true with p and tolerance set as 0.

Source

pub fn have_point_inside(&self, p: PointI32) -> bool

Source

pub fn have_point_on_boundary_or_inside( &self, p: PointI32, boundary_tolerance: usize, ) -> bool

For definition of boundary_tolerance, see BoundingRect::have_point_on_boundary().

Source

pub fn get_closest_point_inside(&self, p: PointI32) -> PointI32

Given a point on the boundary, return the closest point inside the bounding rect. The behavior is undefined unless ‘p’ is a point on boundary (strictly) and the area of this rect is larger than 1.

Source

pub fn get_closest_point_outside(&self, p: PointI32) -> PointI32

Given a point on the boundary, return the closest point outside the bounding rect. Note that if ‘p’ is a corner, there are three closest points, but the diagonal one is always returned. The behavior is undefined unless ‘p’ is a point on boundary (strictly).

Source

pub fn get_boundary_points_from( &self, p: PointI32, clockwise: bool, ) -> Vec<PointI32>

Starting from ‘p’, copy the boundary points into a new Vec following the orientation specified by ‘clockwise’ and return it. The behavior is undefined unless ‘p’ is a point on boundary (strictly).

Trait Implementations§

Source§

impl Bound for BoundingRect

Source§

fn bound(&self) -> BoundingRect

Source§

fn overlaps<B: Bound>(&self, other: &B) -> bool

Source§

impl Clone for BoundingRect

Source§

fn clone(&self) -> BoundingRect

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for BoundingRect

Source§

impl Debug for BoundingRect

Source§

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

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

impl Default for BoundingRect

Source§

fn default() -> BoundingRect

Returns the “default value” for a type. Read more
Source§

impl Eq for BoundingRect

Source§

impl PartialEq for BoundingRect

Source§

fn eq(&self, other: &BoundingRect) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for BoundingRect

Auto Trait Implementations§

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