parry3d_f64/shape/
composite_shape.rs

1use crate::math::{Isometry, Real};
2use crate::partitioning::{IndexedData, Qbvh};
3use crate::query::details::NormalConstraints;
4use crate::shape::Shape;
5
6/// Trait implemented by shapes composed of multiple simpler shapes.
7///
8/// A composite shape is composed of several shapes. For example, this can
9/// be a convex decomposition of a concave shape; or a triangle-mesh.
10#[cfg(feature = "alloc")]
11pub trait SimdCompositeShape {
12    /// Applies a function to one sub-shape of this composite shape.
13    fn map_part_at(
14        &self,
15        shape_id: u32,
16        f: &mut dyn FnMut(Option<&Isometry<Real>>, &dyn Shape, Option<&dyn NormalConstraints>),
17    );
18
19    /// Gets the acceleration structure of the composite shape.
20    fn qbvh(&self) -> &Qbvh<u32>;
21}
22
23#[cfg(feature = "alloc")]
24pub trait TypedSimdCompositeShape {
25    type PartShape: ?Sized + Shape;
26    type PartNormalConstraints: ?Sized + NormalConstraints;
27    type PartId: IndexedData;
28
29    fn map_typed_part_at(
30        &self,
31        shape_id: Self::PartId,
32        f: impl FnMut(Option<&Isometry<Real>>, &Self::PartShape, Option<&Self::PartNormalConstraints>),
33    );
34
35    // TODO: we need this method because the compiler won't want
36    // to cast `&Self::PartShape` to `&dyn Shape` because it complains
37    // that `PartShape` is not `Sized`.
38    fn map_untyped_part_at(
39        &self,
40        shape_id: Self::PartId,
41        f: impl FnMut(Option<&Isometry<Real>>, &dyn Shape, Option<&dyn NormalConstraints>),
42    );
43
44    fn typed_qbvh(&self) -> &Qbvh<Self::PartId>;
45}
46
47#[cfg(feature = "alloc")]
48impl TypedSimdCompositeShape for dyn SimdCompositeShape + '_ {
49    type PartShape = dyn Shape;
50    type PartNormalConstraints = dyn NormalConstraints;
51    type PartId = u32;
52
53    fn map_typed_part_at(
54        &self,
55        shape_id: u32,
56        mut f: impl FnMut(
57            Option<&Isometry<Real>>,
58            &Self::PartShape,
59            Option<&Self::PartNormalConstraints>,
60        ),
61    ) {
62        self.map_part_at(shape_id, &mut f)
63    }
64
65    fn map_untyped_part_at(
66        &self,
67        shape_id: u32,
68        mut f: impl FnMut(Option<&Isometry<Real>>, &dyn Shape, Option<&dyn NormalConstraints>),
69    ) {
70        self.map_part_at(shape_id, &mut f)
71    }
72
73    fn typed_qbvh(&self) -> &Qbvh<Self::PartId> {
74        self.qbvh()
75    }
76}