ncollide3d/query/proximity/
proximity_shape_shape.rs

1use na::RealField;
2
3use crate::math::{Isometry, Point};
4use crate::query::{self, Proximity};
5use crate::shape::{Ball, Plane, Shape};
6
7/// Tests whether two shapes are in intersecting or separated by a distance smaller than `margin`.
8pub fn proximity<N: RealField + Copy>(
9    m1: &Isometry<N>,
10    g1: &dyn Shape<N>,
11    m2: &Isometry<N>,
12    g2: &dyn Shape<N>,
13    margin: N,
14) -> Proximity {
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::proximity_ball_ball(&p1, b1, &p2, b2, margin)
20    } else if let (Some(p1), Some(s2)) = (g1.as_shape::<Plane<N>>(), g2.as_support_map()) {
21        query::proximity_plane_support_map(m1, p1, m2, s2, margin)
22    } else if let (Some(s1), Some(p2)) = (g1.as_support_map(), g2.as_shape::<Plane<N>>()) {
23        query::proximity_support_map_plane(m1, s1, m2, p2, margin)
24    } else if let (Some(s1), Some(s2)) = (g1.as_support_map(), g2.as_support_map()) {
25        query::proximity_support_map_support_map(m1, s1, m2, s2, margin)
26    } else if let Some(c1) = g1.as_composite_shape() {
27        query::proximity_composite_shape_shape(m1, c1, m2, g2, margin)
28    } else if let Some(c2) = g2.as_composite_shape() {
29        query::proximity_shape_composite_shape(m1, g1, m2, c2, margin)
30    } else {
31        panic!("No algorithm known to compute proximity between the given pair of shapes.")
32    }
33}