pub struct Bounds2D<T> { /* private fields */ }
Expand description
A two-dimensional bounding box.
Implementations§
Source§impl<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
pub fn from_position_and_size<P, S>(position: P, size: S) -> Self
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) -> Twhere
T: Add<Output = T>,
pub fn bottom(&self) -> Twhere
T: Add<Output = T>,
pub fn area(&self) -> Twhere
T: Mul<Output = T>,
pub fn size(&self) -> Size2D<T>
pub fn position(&self) -> Point2D<T>
Source§impl<T> Bounds2D<T>
impl<T> Bounds2D<T>
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.