parry3d/query/gjk/
special_support_maps.rs

1use crate::math::{Pose, Real, Vector};
2use crate::shape::SupportMap;
3
4/// A support mapping that is a single point.
5pub struct ConstantPoint(pub Vector);
6
7impl SupportMap for ConstantPoint {
8    #[inline]
9    fn support_point(&self, m: &Pose, _: Vector) -> Vector {
10        m * self.0
11    }
12
13    #[inline]
14    fn support_point_toward(&self, m: &Pose, _: Vector) -> Vector {
15        m * self.0
16    }
17
18    #[inline]
19    fn local_support_point(&self, _: Vector) -> Vector {
20        self.0
21    }
22
23    #[inline]
24    fn local_support_point_toward(&self, _: Vector) -> Vector {
25        self.0
26    }
27}
28
29/// A support mapping that is the point at (0.0, 0.0, 0.0).
30pub struct ConstantOrigin;
31
32impl SupportMap for ConstantOrigin {
33    #[inline]
34    fn support_point(&self, m: &Pose, _: Vector) -> Vector {
35        m.translation
36    }
37
38    #[inline]
39    fn support_point_toward(&self, m: &Pose, _: Vector) -> Vector {
40        m.translation
41    }
42
43    #[inline]
44    fn local_support_point(&self, _: Vector) -> Vector {
45        Vector::ZERO
46    }
47
48    #[inline]
49    fn local_support_point_toward(&self, _: Vector) -> Vector {
50        Vector::ZERO
51    }
52}
53
54/// The Minkowski sum of a shape and a ball.
55pub struct DilatedShape<'a, S: ?Sized + SupportMap> {
56    /// The shape involved in the Minkowski sum.
57    pub shape: &'a S,
58    /// The radius of the ball involved in the Minkoski sum.
59    pub radius: Real,
60}
61
62impl<S: ?Sized + SupportMap> SupportMap for DilatedShape<'_, S> {
63    #[inline]
64    fn support_point(&self, m: &Pose, dir: Vector) -> Vector {
65        let normalized_dir = dir.normalize_or_zero();
66        self.support_point_toward(m, normalized_dir)
67    }
68
69    #[inline]
70    fn support_point_toward(&self, m: &Pose, dir: Vector) -> Vector {
71        self.shape.support_point_toward(m, dir) + dir * self.radius
72    }
73
74    #[inline]
75    fn local_support_point(&self, dir: Vector) -> Vector {
76        let normalized_dir = dir.normalize_or_zero();
77        self.local_support_point_toward(normalized_dir)
78    }
79
80    #[inline]
81    fn local_support_point_toward(&self, dir: Vector) -> Vector {
82        self.shape.local_support_point_toward(dir) + dir * self.radius
83    }
84}