ncollide3d/query/algorithms/
special_support_maps.rs

1use na::{RealField, Unit};
2
3use crate::math::{Isometry, Point, Vector};
4use crate::shape::SupportMap;
5
6/// A support mapping that is always equal to the origin, independently from its transform.
7pub struct ConstantOrigin;
8
9impl<N: RealField + Copy> SupportMap<N> for ConstantOrigin {
10    #[inline]
11    fn support_point(&self, _: &Isometry<N>, _: &Vector<N>) -> Point<N> {
12        Point::origin()
13    }
14
15    #[inline]
16    fn support_point_toward(&self, _: &Isometry<N>, _: &Unit<Vector<N>>) -> Point<N> {
17        Point::origin()
18    }
19
20    #[inline]
21    fn local_support_point(&self, _: &Vector<N>) -> Point<N> {
22        Point::origin()
23    }
24
25    #[inline]
26    fn local_support_point_toward(&self, _: &Unit<Vector<N>>) -> Point<N> {
27        Point::origin()
28    }
29}
30
31/// The Minkowski sum of a shape and a ball.
32pub struct DilatedShape<'a, N: RealField + Copy, S: ?Sized + SupportMap<N>> {
33    /// The shape involved in the Minkowski sum.
34    pub shape: &'a S,
35    /// The radius of the ball involved in the Minkoski sum.
36    pub radius: N,
37}
38
39impl<'a, N: RealField + Copy, S: ?Sized + SupportMap<N>> SupportMap<N> for DilatedShape<'a, N, S> {
40    #[inline]
41    fn support_point(&self, m: &Isometry<N>, dir: &Vector<N>) -> Point<N> {
42        self.support_point_toward(m, &Unit::new_normalize(*dir))
43    }
44
45    #[inline]
46    fn support_point_toward(&self, m: &Isometry<N>, dir: &Unit<Vector<N>>) -> Point<N> {
47        self.shape.support_point_toward(m, dir) + **dir * self.radius
48    }
49
50    #[inline]
51    fn local_support_point(&self, dir: &Vector<N>) -> Point<N> {
52        self.local_support_point_toward(&Unit::new_normalize(*dir))
53    }
54
55    #[inline]
56    fn local_support_point_toward(&self, dir: &Unit<Vector<N>>) -> Point<N> {
57        self.shape.local_support_point_toward(dir) + **dir * self.radius
58    }
59}