ncollide3d/bounding_volume/bounding_volume.rs
1use crate::math::{Isometry, Point};
2use na::RealField;
3
4/// Traits of objects having a bounding volume.
5pub trait HasBoundingVolume<N: RealField + Copy, BV> {
6 /// The bounding volume of `self` transformed by `m`.
7 fn bounding_volume(&self, m: &Isometry<N>) -> BV;
8 /// The bounding volume of `self`.
9 fn local_bounding_volume(&self) -> BV {
10 self.bounding_volume(&Isometry::identity())
11 }
12}
13
14/// Trait of bounding volumes.
15///
16/// Bounding volumes are coarse approximations of shapes. It usually have constant time
17/// intersection, inclusion test. Two bounding volume must also be mergeable into a bigger bounding
18/// volume.
19pub trait BoundingVolume<N: RealField + Copy>: std::fmt::Debug {
20 // FIXME: keep that ? What about non-spacial bounding volumes (e.g. bounding cones, curvature
21 // bounds, etc.) ?
22 /// Returns a point inside of this bounding volume. This is ideally its center.
23 fn center(&self) -> Point<N>;
24
25 /// Checks if this bounding volume intersect with another one.
26 fn intersects(&self, _: &Self) -> bool;
27
28 /// Checks if this bounding volume contains another one.
29 fn contains(&self, _: &Self) -> bool;
30
31 /// Merges this bounding volume with another one. The merge is done in-place.
32 fn merge(&mut self, _: &Self);
33
34 /// Merges this bounding volume with another one.
35 fn merged(&self, _: &Self) -> Self;
36
37 /// Enlarges this bounding volume.
38 fn loosen(&mut self, _: N);
39
40 /// Creates a new, enlarged version, of this bounding volume.
41 fn loosened(&self, _: N) -> Self;
42
43 /// Tighten this bounding volume.
44 fn tighten(&mut self, _: N);
45
46 /// Creates a new, tightened version, of this bounding volume.
47 fn tightened(&self, _: N) -> Self;
48}