parry2d/query/distance/
distance_support_map_support_map.rs1use crate::math::{Pose, Real, Vector};
2use crate::query::gjk::{self, CsoPoint, GJKResult, VoronoiSimplex};
3use crate::shape::SupportMap;
4use num::Bounded;
5
6pub fn distance_support_map_support_map<G1, G2>(pos12: &Pose, g1: &G1, g2: &G2) -> Real
8where
9 G1: ?Sized + SupportMap,
10 G2: ?Sized + SupportMap,
11{
12 distance_support_map_support_map_with_params(pos12, g1, g2, &mut VoronoiSimplex::new(), None)
13}
14
15pub fn distance_support_map_support_map_with_params<G1, G2>(
19 pos12: &Pose,
20 g1: &G1,
21 g2: &G2,
22 simplex: &mut VoronoiSimplex,
23 init_dir: Option<Vector>,
24) -> Real
25where
26 G1: ?Sized + SupportMap,
27 G2: ?Sized + SupportMap,
28{
29 let dir = init_dir.unwrap_or_else(|| -pos12.translation);
31
32 let normalized_dir =
33 if dir.length_squared() > crate::math::DEFAULT_EPSILON * crate::math::DEFAULT_EPSILON {
34 dir.normalize()
35 } else {
36 Vector::X
37 };
38
39 simplex.reset(CsoPoint::from_shapes(pos12, g1, g2, normalized_dir));
40
41 match gjk::closest_points(pos12, g1, g2, Real::max_value(), true, simplex) {
42 GJKResult::Intersection => 0.0,
43 GJKResult::ClosestPoints(p1, p2, _) => (p1 - p2).length(),
44 GJKResult::Proximity(_) => unreachable!(),
45 GJKResult::NoIntersection(_) => 0.0, }
47}