ncollide3d/bounding_volume/
spatialized_normal_cone.rs

1use crate::bounding_volume::{BoundingVolume, CircularCone, AABB};
2use crate::math::Point;
3use na::RealField;
4
5/// The combination of an AABB with a circular cone to bound both the space occupied by an geometry and its normals.
6#[derive(Clone, Debug)]
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8pub struct SpatializedNormalCone<N: RealField + Copy> {
9    /// An AABB bounding the space occupied by a geometry.
10    pub aabb: AABB<N>,
11    /// A circular cone bounding the normals of a geometry.
12    pub normals: CircularCone<N>,
13}
14
15impl<N: RealField + Copy> BoundingVolume<N> for SpatializedNormalCone<N> {
16    fn center(&self) -> Point<N> {
17        self.aabb.center()
18    }
19
20    fn intersects(&self, other: &Self) -> bool {
21        self.aabb.intersects(&other.aabb) && self.normals.double_cones_intersect(&other.normals)
22    }
23
24    fn contains(&self, other: &Self) -> bool {
25        self.aabb.contains(&other.aabb) && self.normals.contains(&other.normals)
26    }
27
28    fn merge(&mut self, other: &Self) {
29        self.aabb.merge(&other.aabb);
30        self.normals.merge(&other.normals);
31    }
32
33    fn merged(&self, other: &Self) -> Self {
34        SpatializedNormalCone {
35            aabb: self.aabb.merged(&other.aabb),
36            normals: self.normals.merged(&other.normals),
37        }
38    }
39
40    fn loosen(&mut self, margin: N) {
41        self.aabb.loosen(margin)
42    }
43
44    fn loosened(&self, margin: N) -> Self {
45        SpatializedNormalCone {
46            aabb: self.aabb.loosened(margin),
47            normals: self.normals,
48        }
49    }
50
51    fn tighten(&mut self, margin: N) {
52        self.aabb.tighten(margin)
53    }
54
55    fn tightened(&self, margin: N) -> Self {
56        SpatializedNormalCone {
57            aabb: self.aabb.tightened(margin),
58            normals: self.normals,
59        }
60    }
61}