parry2d/bounding_volume/bounding_volume.rs
1use crate::math::{Real, Vector};
2
3/// Trait of bounding volumes.
4///
5/// Bounding volumes are coarse approximations of shapes. It usually have constant time
6/// intersection, inclusion test. Two bounding volume must also be mergeable into a bigger bounding
7/// volume.
8pub trait BoundingVolume {
9 // TODO: keep that ? What about non-spacial bounding volumes (e.g. bounding cones, curvature
10 // bounds, etc.) ?
11 /// Returns a point inside of this bounding volume. This is ideally its center.
12 fn center(&self) -> Vector;
13
14 /// Checks if this bounding volume intersect with another one.
15 fn intersects(&self, _: &Self) -> bool;
16
17 /// Checks if this bounding volume contains another one.
18 fn contains(&self, _: &Self) -> bool;
19
20 /// Merges this bounding volume with another one. The merge is done in-place.
21 ///
22 /// Due to floating-point rounding, the merged volume is not guaranteed to strictly
23 /// [`contain`](Self::contains) both input volumes. Use [`loosened`](Self::loosened)
24 /// with a small margin if strict containment is required.
25 fn merge(&mut self, _: &Self);
26
27 /// Merges this bounding volume with another one.
28 ///
29 /// Due to floating-point rounding, the merged volume is not guaranteed to strictly
30 /// [`contain`](Self::contains) both input volumes. Use [`loosened`](Self::loosened)
31 /// with a small margin if strict containment is required.
32 fn merged(&self, _: &Self) -> Self;
33
34 /// Enlarges this bounding volume.
35 fn loosen(&mut self, _: Real);
36
37 /// Creates a new, enlarged version, of this bounding volume.
38 fn loosened(&self, _: Real) -> Self;
39
40 /// Tighten this bounding volume.
41 fn tighten(&mut self, _: Real);
42
43 /// Creates a new, tightened version, of this bounding volume.
44 fn tightened(&self, _: Real) -> Self;
45}