1use crate::math::{Isometry, Point, Vector};
2use crate::shape::{ConvexPolygonalFeature, SupportMap};
3use na::{RealField, Unit};
45/// An identifier of a feature of a convex polyhedron.
6///
7/// This identifier is shape-dependent and is seach that it
8/// allows an efficient retrieval of the geometric information of the
9/// feature.
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
12pub enum FeatureId {
13/// Shape-dependent identifier of a vertex.
14Vertex(usize),
15#[cfg(feature = "dim3")]
16/// Shape-dependent identifier of an edge.
17Edge(usize),
18/// Shape-dependent identifier of a face.
19Face(usize),
20// XXX: remove this variant.
21/// Unknown identifier.
22Unknown,
23}
2425impl FeatureId {
26/// Revries the value of the identifier if `self` is a vertex.
27pub fn unwrap_vertex(self) -> usize {
28match self {
29 FeatureId::Vertex(id) => id,
30_ => panic!("The feature id does not identify a vertex."),
31 }
32 }
3334/// Revries the value of the identifier if `self` is an edge.
35#[cfg(feature = "dim3")]
36pub fn unwrap_edge(self) -> usize {
37match self {
38 FeatureId::Edge(id) => id,
39_ => panic!("The feature id does not identify an edge."),
40 }
41 }
4243/// Retrieves the value of the identifier if `self` is a face.
44pub fn unwrap_face(self) -> usize {
45match self {
46 FeatureId::Face(id) => id,
47_ => panic!("The feature id does not identify a face."),
48 }
49 }
50}
5152/// Trait implemented by all convex polyhedron.
53pub trait ConvexPolyhedron<N: RealField + Copy>: SupportMap<N> {
54/// Gets the specified vertex in the shape local-space.
55fn vertex(&self, id: FeatureId) -> Point<N>;
56/// Fill `face` with the geometric description of the specified face, in the shape's local-space.
57fn face(&self, id: FeatureId, face: &mut ConvexPolygonalFeature<N>);
58#[cfg(feature = "dim3")]
59/// Get the specified edge's vertices (in the shape local-space) and the vertices' identifiers.
60fn edge(&self, id: FeatureId) -> (Point<N>, Point<N>, FeatureId, FeatureId);
6162/// Returns any normal from the normal cone of the given feature.
63fn feature_normal(&self, feature: FeatureId) -> Unit<Vector<N>>;
6465/// Retrieve the face (in world-space) with a normal that maximizes the scalar product with `dir`.
66fn support_face_toward(
67&self,
68 transform: &Isometry<N>,
69 dir: &Unit<Vector<N>>,
70 out: &mut ConvexPolygonalFeature<N>,
71 );
7273/// Retrieve the feature (in world-space) which normal cone contains `dir`.
74fn support_feature_toward(
75&self,
76 transform: &Isometry<N>,
77 dir: &Unit<Vector<N>>,
78 _angle: N,
79 out: &mut ConvexPolygonalFeature<N>,
80 );
8182/// Retrieve the identifier of the feature which normal cone contains `dir`.
83fn support_feature_id_toward(&self, local_dir: &Unit<Vector<N>>) -> FeatureId;
84}