ncollide3d/query/distance/
distance.rs1use crate::math::{Isometry, Point};
2use crate::query;
3use crate::shape::{Ball, Plane, Shape};
4use na::RealField;
5
6pub fn distance<N: RealField + Copy>(
10 m1: &Isometry<N>,
11 g1: &dyn Shape<N>,
12 m2: &Isometry<N>,
13 g2: &dyn Shape<N>,
14) -> N {
15 if let (Some(b1), Some(b2)) = (g1.as_shape::<Ball<N>>(), g2.as_shape::<Ball<N>>()) {
16 let p1 = Point::from(m1.translation.vector);
17 let p2 = Point::from(m2.translation.vector);
18
19 query::distance_ball_ball(&p1, b1, &p2, b2)
20 } else if let (Some(p1), Some(s2)) = (g1.as_shape::<Plane<N>>(), g2.as_support_map()) {
21 query::distance_plane_support_map(m1, p1, m2, s2)
22 } else if let (Some(s1), Some(p2)) = (g1.as_support_map(), g2.as_shape::<Plane<N>>()) {
23 query::distance_support_map_plane(m1, s1, m2, p2)
24 } else if let (Some(s1), Some(s2)) = (g1.as_support_map(), g2.as_support_map()) {
25 query::distance_support_map_support_map(m1, s1, m2, s2)
26 } else if let Some(c1) = g1.as_composite_shape() {
27 query::distance_composite_shape_shape(m1, c1, m2, g2)
28 } else if let Some(c2) = g2.as_composite_shape() {
29 query::distance_shape_composite_shape(m1, g1, m2, c2)
30 } else {
31 panic!("No algorithm known to compute a contact point between the given pair of shapes.")
32 }
33}