parry3d/shape/support_map.rs
1//! Traits for support mapping based shapes.
2
3use crate::math::{Isometry, Point, Real, Vector};
4use na::Unit;
5
6/// Traits of convex shapes representable by a support mapping function.
7///
8/// # Parameters:
9/// * V - type of the support mapping direction argument and of the returned point.
10pub trait SupportMap {
11 // Evaluates the support function of this shape.
12 //
13 // A support function is a function associating a vector to the shape point which maximizes
14 // their dot product.
15 fn local_support_point(&self, dir: &Vector<Real>) -> Point<Real>;
16
17 /// Same as `self.local_support_point` except that `dir` is normalized.
18 fn local_support_point_toward(&self, dir: &Unit<Vector<Real>>) -> Point<Real> {
19 self.local_support_point(dir.as_ref())
20 }
21
22 // Evaluates the support function of this shape transformed by `transform`.
23 //
24 // A support function is a function associating a vector to the shape point which maximizes
25 // their dot product.
26 fn support_point(&self, transform: &Isometry<Real>, dir: &Vector<Real>) -> Point<Real> {
27 let local_dir = transform.inverse_transform_vector(dir);
28 transform * self.local_support_point(&local_dir)
29 }
30
31 /// Same as `self.support_point` except that `dir` is normalized.
32 fn support_point_toward(
33 &self,
34 transform: &Isometry<Real>,
35 dir: &Unit<Vector<Real>>,
36 ) -> Point<Real> {
37 let local_dir = Unit::new_unchecked(transform.inverse_transform_vector(dir));
38 transform * self.local_support_point_toward(&local_dir)
39 }
40}