ncollide3d/shape/
convex_polyhedron.rs1use crate::math::{Isometry, Point, Vector};
2use crate::shape::{ConvexPolygonalFeature, SupportMap};
3use na::{RealField, Unit};
4
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
12pub enum FeatureId {
13    Vertex(usize),
15    #[cfg(feature = "dim3")]
16    Edge(usize),
18    Face(usize),
20    Unknown,
23}
24
25impl FeatureId {
26    pub fn unwrap_vertex(self) -> usize {
28        match self {
29            FeatureId::Vertex(id) => id,
30            _ => panic!("The feature id does not identify a vertex."),
31        }
32    }
33
34    #[cfg(feature = "dim3")]
36    pub fn unwrap_edge(self) -> usize {
37        match self {
38            FeatureId::Edge(id) => id,
39            _ => panic!("The feature id does not identify an edge."),
40        }
41    }
42
43    pub fn unwrap_face(self) -> usize {
45        match self {
46            FeatureId::Face(id) => id,
47            _ => panic!("The feature id does not identify a face."),
48        }
49    }
50}
51
52pub trait ConvexPolyhedron<N: RealField + Copy>: SupportMap<N> {
54    fn vertex(&self, id: FeatureId) -> Point<N>;
56    fn face(&self, id: FeatureId, face: &mut ConvexPolygonalFeature<N>);
58    #[cfg(feature = "dim3")]
59    fn edge(&self, id: FeatureId) -> (Point<N>, Point<N>, FeatureId, FeatureId);
61
62    fn feature_normal(&self, feature: FeatureId) -> Unit<Vector<N>>;
64
65    fn support_face_toward(
67        &self,
68        transform: &Isometry<N>,
69        dir: &Unit<Vector<N>>,
70        out: &mut ConvexPolygonalFeature<N>,
71    );
72
73    fn support_feature_toward(
75        &self,
76        transform: &Isometry<N>,
77        dir: &Unit<Vector<N>>,
78        _angle: N,
79        out: &mut ConvexPolygonalFeature<N>,
80    );
81
82    fn support_feature_id_toward(&self, local_dir: &Unit<Vector<N>>) -> FeatureId;
84}