pub struct Bounds2D<T> { /* private fields */ }
Expand description
A two-dimensional bounding box.
Implementations
sourceimpl<T> Bounds2D<T> where
T: Copy,
impl<T> Bounds2D<T> where
T: Copy,
sourcepub fn splat(value: T) -> Self
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));
sourcepub fn from_position_and_size<P, S>(position: P, size: S) -> Self where
P: ToPoint2D<T>,
S: ToSize2D<T>,
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));
sourcepub fn with_position<P: ToPoint2D<T>>(&self, point: P) -> Bounds2D<T>
pub fn with_position<P: ToPoint2D<T>>(&self, point: P) -> Bounds2D<T>
Creates a new Bounds2D with the specified position.
sourcepub fn with_size<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
pub fn with_size<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
Creates a new Bounds2D with the specified size.
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 where
T: Add<Output = T>,
pub fn bottom(&self) -> T where
T: Add<Output = T>,
pub fn area(&self) -> T where
T: Mul<Output = T>,
pub fn size(&self) -> Size2D<T>
pub fn position(&self) -> Point2D<T>
sourceimpl<T> Bounds2D<T> where
T: Num + Copy + Ord,
impl<T> Bounds2D<T> where
T: Num + Copy + Ord,
sourcepub fn grow<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
pub fn grow<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
See Size2D::grow()
for more information.
sourcepub fn shrink<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
pub fn shrink<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
See Size2D::shrink()
for more information.
sourcepub fn constrain<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>
pub fn constrain<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>
See Size2D::constrain()
for more information.
sourcepub fn max_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
pub fn max_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
See Size2D::max_area()
for more information.
sourcepub fn min_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
pub fn min_area<S: ToSize2D<T>>(&self, size: S) -> Bounds2D<T>
See Size2D::min_area()
for more information.
sourcepub fn clamp_area<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>
pub fn clamp_area<S: ToSize2D<T>>(&self, min: S, max: S) -> Bounds2D<T>
See Size2D::clamp_area()
for more information.
Trait Implementations
sourceimpl<T> From<Bounds2D<T>> for (T, T, T, T)
impl<T> From<Bounds2D<T>> for (T, T, T, T)
impl<T: Copy> Copy for Bounds2D<T>
impl<T> StructuralPartialEq for Bounds2D<T>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more