Struct Bounds2D

Source
pub struct Bounds2D<T> { /* private fields */ }
Expand description

A two-dimensional bounding box.

Implementations§

Source§

impl<T> Bounds2D<T>
where T: Copy,

Source

pub fn new(x: T, y: T, width: T, height: T) -> Self

Creates a new Bounds2D. In most cases you should use the bounds!() macro instead.

§Examples
let bounds = Bounds2D::new(20, 50, 80, 90);

// Prefer doing this instead
let bounds = bounds!(20, 50, 80, 90);
Source

pub fn splat(value: T) -> Self

Returns a new Bounds2D where all components are set to value.

Prefer using the splat syntax with the macro instead of calling this directly.

§Examples
// This is acceptable, but...
let bounds = Bounds2D::splat(8);

// ...this is the preferred way
let bounds = bounds!(8; 2);

assert_eq!(bounds, bounds!(8, 8, 8, 8));
Source

pub fn from_position_and_size<P, S>(position: P, size: S) -> Self
where P: ToPoint2D<T>, S: ToSize2D<T>,

Creates a new Bounds2D from a position and size. This is useful when you have a size and position, and want to create a bounds out of it.

However, if you already have a Size2D or a Point2D, you should use the .with_ method instead.

§Examples
let bounds = Bounds2D::from_position_and_size(point!(20, 40), size!(10, 10));

// Prefer doing this instead
let bounds = point!(20, 40).with_size(size!(10, 10));
Source

pub fn with_position<P: ToPoint2D<T>>(&self, point: P) -> Bounds2D<T>

Creates a new Bounds2D with the specified position.

Source

pub fn with_size<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>

Creates a new Bounds2D with the specified size.

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
where T: Add<Output = T>,

Source

pub fn bottom(&self) -> T
where T: Add<Output = T>,

Source

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

Source

pub fn size(&self) -> Size2D<T>

Source

pub fn position(&self) -> Point2D<T>

Source§

impl<T> Bounds2D<T>
where T: Num + Copy + Ord,

Source

pub fn grow<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>

See Size2D::grow() for more information.

Source

pub fn shrink<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>

See Size2D::shrink() for more information.

Source

pub fn constrain<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>

See Size2D::constrain() for more information.

Source

pub fn max_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>

See Size2D::max_area() for more information.

Source

pub fn min_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>

See Size2D::min_area() for more information.

Source

pub fn clamp_area<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>

See Size2D::clamp_area() for more information.

Trait Implementations§

Source§

impl<T> Add<Size2D<T>> for Bounds2D<T>
where T: Num + Copy,

Source§

type Output = Bounds2D<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Size2D<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Add<Vector2D<T, Offset>> for Bounds2D<T>
where T: Num + Copy,

Source§

type Output = Bounds2D<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Offset2D<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Bounds2D<T>

Source§

fn clone(&self) -> Bounds2D<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> Debug for Bounds2D<T>

Source§

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

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

impl<T: Default> Default for Bounds2D<T>

Source§

fn default() -> Bounds2D<T>

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

impl<T> From<Bounds2D<T>> for [T; 4]

Source§

fn from(bounds: Bounds2D<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Bounds2D<T>> for (T, T, T, T)

Source§

fn from(bounds: Bounds2D<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash> Hash for Bounds2D<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IntoBounds2D<T> for Bounds2D<T>

Source§

impl<T: PartialEq> PartialEq for Bounds2D<T>

Source§

fn eq(&self, other: &Bounds2D<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> Sub<Size2D<T>> for Bounds2D<T>
where T: Num + Copy,

Source§

type Output = Bounds2D<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Size2D<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T> Sub<Vector2D<T, Offset>> for Bounds2D<T>
where T: Num + Copy,

Source§

type Output = Bounds2D<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Offset2D<T>) -> Self::Output

Performs the - operation. Read more
Source§

impl<T: Copy> Copy for Bounds2D<T>

Source§

impl<T> StructuralPartialEq for Bounds2D<T>

Auto Trait Implementations§

§

impl<T> Freeze for Bounds2D<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Bounds2D<T>
where T: RefUnwindSafe,

§

impl<T> Send for Bounds2D<T>
where T: Send,

§

impl<T> Sync for Bounds2D<T>
where T: Sync,

§

impl<T> Unpin for Bounds2D<T>
where T: Unpin,

§

impl<T> UnwindSafe for Bounds2D<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> 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.