pub trait BoundingVolume: Sized {
type Translation: Clone + Copy + PartialEq;
type Rotation: Clone + Copy + PartialEq;
type HalfSize;
Show 14 methods
// Required methods
fn center(&self) -> Self::Translation;
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: impl Into<Self::HalfSize>) -> Self;
fn shrink(&self, amount: impl Into<Self::HalfSize>) -> Self;
fn scale_around_center(&self, scale: impl Into<Self::HalfSize>) -> Self;
fn translate_by(&mut self, translation: impl Into<Self::Translation>);
fn rotate_by(&mut self, rotation: impl Into<Self::Rotation>);
// Provided methods
fn transformed_by(
self,
translation: impl Into<Self::Translation>,
rotation: impl Into<Self::Rotation>,
) -> Self { ... }
fn transform_by(
&mut self,
translation: impl Into<Self::Translation>,
rotation: impl Into<Self::Rotation>,
) { ... }
fn translated_by(self, translation: impl Into<Self::Translation>) -> Self { ... }
fn rotated_by(self, rotation: impl Into<Self::Rotation>) -> 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§
Sourcetype Translation: Clone + Copy + PartialEq
type Translation: Clone + Copy + PartialEq
The position type used for the volume. This should be Vec2
for 2D and Vec3
for 3D.
Required Methods§
Sourcefn center(&self) -> Self::Translation
fn center(&self) -> Self::Translation
Returns the center of the bounding volume.
Sourcefn visible_area(&self) -> f32
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.
Sourcefn merge(&self, other: &Self) -> Self
fn merge(&self, other: &Self) -> Self
Computes the smallest bounding volume that contains both self
and other
.
Sourcefn grow(&self, amount: impl Into<Self::HalfSize>) -> Self
fn grow(&self, amount: impl Into<Self::HalfSize>) -> Self
Increases the size of the bounding volume in each direction by the given amount.
Sourcefn shrink(&self, amount: impl Into<Self::HalfSize>) -> Self
fn shrink(&self, amount: impl Into<Self::HalfSize>) -> Self
Decreases the size of the bounding volume in each direction by the given amount.
Sourcefn scale_around_center(&self, scale: impl Into<Self::HalfSize>) -> Self
fn scale_around_center(&self, scale: impl Into<Self::HalfSize>) -> Self
Scale the size of the bounding volume around its center by the given amount
Sourcefn translate_by(&mut self, translation: impl Into<Self::Translation>)
fn translate_by(&mut self, translation: impl Into<Self::Translation>)
Translates the bounding volume by the given translation.
Provided Methods§
Sourcefn transformed_by(
self,
translation: impl Into<Self::Translation>,
rotation: impl Into<Self::Rotation>,
) -> Self
fn transformed_by( self, translation: impl Into<Self::Translation>, rotation: impl Into<Self::Rotation>, ) -> Self
Transforms the bounding volume by first rotating it around the origin and then applying a translation.
Sourcefn transform_by(
&mut self,
translation: impl Into<Self::Translation>,
rotation: impl Into<Self::Rotation>,
)
fn transform_by( &mut self, translation: impl Into<Self::Translation>, rotation: impl Into<Self::Rotation>, )
Transforms the bounding volume by first rotating it around the origin and then applying a translation.
Sourcefn translated_by(self, translation: impl Into<Self::Translation>) -> Self
fn translated_by(self, translation: impl Into<Self::Translation>) -> Self
Translates the bounding volume by the given translation.
Sourcefn rotated_by(self, rotation: impl Into<Self::Rotation>) -> Self
fn rotated_by(self, rotation: impl Into<Self::Rotation>) -> Self
Rotates the bounding volume around the origin by the given rotation.
The result is a combination of the original volume and the rotated volume, so it is guaranteed to be either the same size or larger than the original.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.