pub trait BoundingVolume {
    type Position: Clone + Copy + PartialEq;
    type HalfSize;

    // Required methods
    fn center(&self) -> Self::Position;
    fn half_size(&self) -> Self::HalfSize;
    fn visible_area(&self) -> f32;
    fn contains(&self, other: &Self) -> bool;
    fn merge(&self, other: &Self) -> Self;
    fn grow(&self, amount: Self::HalfSize) -> Self;
    fn shrink(&self, amount: Self::HalfSize) -> Self;
}
Expand description

A trait that generalizes different bounding volumes. Bounding volumes are simplified shapes that are used to get simpler ways to check for overlapping elements or finding intersections.

This trait supports both 2D and 3D bounding shapes.

Required Associated Types§

source

type Position: Clone + Copy + PartialEq

The position type used for the volume. This should be Vec2 for 2D and Vec3 for 3D.

source

type HalfSize

The type used for the size of the bounding volume. Usually a half size. For example an f32 radius for a circle, or a Vec3 with half sizes for x, y and z for a 3D axis-aligned bounding box

Required Methods§

source

fn center(&self) -> Self::Position

Returns the center of the bounding volume.

source

fn half_size(&self) -> Self::HalfSize

Returns the half size of the bounding volume.

source

fn visible_area(&self) -> f32

Computes the visible surface area of the bounding volume. This method can be useful to make decisions about merging bounding volumes, using a Surface Area Heuristic.

For 2D shapes this would simply be the area of the shape. For 3D shapes this would usually be half the area of the shape.

source

fn contains(&self, other: &Self) -> bool

Checks if this bounding volume contains another one.

source

fn merge(&self, other: &Self) -> Self

Computes the smallest bounding volume that contains both self and other.

source

fn grow(&self, amount: Self::HalfSize) -> Self

Increase the size of the bounding volume in each direction by the given amount

source

fn shrink(&self, amount: Self::HalfSize) -> Self

Decrease the size of the bounding volume in each direction by the given amount

Object Safety§

This trait is not object safe.

Implementors§