parry3d/query/intersection_test/
intersection_test_support_map_support_map.rs

1use crate::math::{Pose, Vector};
2use crate::query::gjk::{self, CsoPoint, GJKResult, VoronoiSimplex};
3use crate::shape::SupportMap;
4
5/// Intersection test between support-mapped shapes (`Cuboid`, `ConvexHull`, etc.)
6pub fn intersection_test_support_map_support_map<G1, G2>(pos12: &Pose, g1: &G1, g2: &G2) -> bool
7where
8    G1: ?Sized + SupportMap,
9    G2: ?Sized + SupportMap,
10{
11    intersection_test_support_map_support_map_with_params(
12        pos12,
13        g1,
14        g2,
15        &mut VoronoiSimplex::new(),
16        None,
17    )
18    .0
19}
20
21/// Intersection test between support-mapped shapes (`Cuboid`, `ConvexHull`, etc.)
22///
23/// This allows a more fine grained control other the underlying GJK algorithm.
24pub fn intersection_test_support_map_support_map_with_params<G1, G2>(
25    pos12: &Pose,
26    g1: &G1,
27    g2: &G2,
28    simplex: &mut VoronoiSimplex,
29    init_dir: Option<Vector>,
30) -> (bool, Vector)
31where
32    G1: ?Sized + SupportMap,
33    G2: ?Sized + SupportMap,
34{
35    let dir = if let Some(init_dir) = init_dir {
36        init_dir
37    } else if let Some(init_dir) = (pos12.translation).try_normalize() {
38        init_dir
39    } else {
40        Vector::X
41    };
42
43    simplex.reset(CsoPoint::from_shapes(pos12, g1, g2, dir));
44
45    match gjk::closest_points(pos12, g1, g2, 0.0, false, simplex) {
46        GJKResult::Intersection => (true, dir),
47        GJKResult::Proximity(dir) => (false, dir),
48        GJKResult::NoIntersection(dir) => (false, dir),
49        GJKResult::ClosestPoints(..) => unreachable!(),
50    }
51}