[−][src]Struct physics2d::Bounds
A 2D bounding volume in space.
Bounding volumes are often used to cheaply approximate shapes and objects. The structure of
a Bounds
ensures that all operations - including expansion, intersection and overlap checks -
are performed quickly and efficiently.
Methods
impl Bounds
[src]
pub fn new(min: Vec2, max: Vec2) -> Bounds
[src]
Creates a new Bounds
from the given minimum and maximum corner points.
pub fn center_extents(center: Vec2, extents: Vec2) -> Bounds
[src]
Creates a new Bounds
with the given center and extents. extents
is the vector
from the center to the farthest point (max
) of the bounding volume. min
and max
of the
created bounding volume are center - extents
and center + extents
respectively.
Example
let b = Bounds::center_extents(Vec2::ONE, Vec2::new(1.0, 3.0)); assert_eq!(b, Bounds::new(Vec2::new(0.0, -2.0), Vec2::new(2.0, 4.0)));
pub fn perimeter(&self) -> f32
[src]
Returns the perimeter of the given bounding volume.
Example
let b = Bounds::center_extents(Vec2::ONE, Vec2::new(2.0, 15.1)); assert_eq!(b.perimeter(), 2.0 * 2.0 * (2.0 + 15.1));
pub fn intersects(&self, other: &Bounds) -> bool
[src]
Checks whether two Bounds
are intersecting.
Example
let b1 = Bounds::center_extents(Vec2::ONE, Vec2::ONE); let b2 = Bounds::center_extents(Vec2::new(0.5, 0.5), Vec2::ONE); assert!(b1.intersects(&b2));
pub fn contains(&self, other: &Bounds) -> bool
[src]
Checks whether this Bounds
fully contains the other.
Example
let b1 = Bounds::center_extents(Vec2::ONE, Vec2::ONE); let b2 = Bounds::center_extents(Vec2::new(0.5, 0.5), Vec2::new(0.5, 0.5)); assert!(b1.contains(&b2));
pub fn union(&self, other: &Bounds) -> Bounds
[src]
Returns a bounding volume that completely encompasses both the bounding volume represented
by self
and other
.
Example
let b1 = Bounds::center_extents(Vec2::ONE, Vec2::ONE); let b2 = Bounds::center_extents(Vec2::new(0.5, 0.5), Vec2::ONE); let union = Bounds::new(Vec2::new(-0.5, -0.5), Vec2::new(2.0, 2.0)); assert_eq!(b1.union(&b2), union); let b3 = Bounds::new(Vec2::new(-0.5, -0.5), Vec2::new(-0.4, -0.4)); let b4 = Bounds::new(Vec2::new(1.9, -0.325), Vec2::new(2.0, 2.0)); assert_eq!(b3.union(&b4), union);
pub fn expand(&self, margin: f32) -> Bounds
[src]
Expands the Bounds
in all directions by margin
.
Example
let b1 = Bounds::center_extents(Vec2::ONE, Vec2::new(0.5, 0.5)); let b2 = Bounds::center_extents(Vec2::ONE, Vec2::ONE); assert_eq!(b1.expand(0.5), b2);
Trait Implementations
impl Copy for Bounds
[src]
impl Clone for Bounds
[src]
fn clone(&self) -> Bounds
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<Bounds> for Bounds
[src]
impl Debug for Bounds
[src]
Auto Trait Implementations
impl Sync for Bounds
impl Unpin for Bounds
impl Send for Bounds
impl UnwindSafe for Bounds
impl RefUnwindSafe for Bounds
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,