use na::{self, Unit};
use crate::math::{Isometry, Real, Vector};
use crate::query::gjk::{self, CSOPoint, GJKResult, VoronoiSimplex};
use crate::shape::SupportMap;
pub fn intersection_test_support_map_support_map<G1, G2>(
pos12: &Isometry<Real>,
g1: &G1,
g2: &G2,
) -> bool
where
G1: ?Sized + SupportMap,
G2: ?Sized + SupportMap,
{
intersection_test_support_map_support_map_with_params(
pos12,
g1,
g2,
&mut VoronoiSimplex::new(),
None,
)
.0
}
pub fn intersection_test_support_map_support_map_with_params<G1, G2>(
pos12: &Isometry<Real>,
g1: &G1,
g2: &G2,
simplex: &mut VoronoiSimplex,
init_dir: Option<Unit<Vector<Real>>>,
) -> (bool, Unit<Vector<Real>>)
where
G1: ?Sized + SupportMap,
G2: ?Sized + SupportMap,
{
let dir = if let Some(init_dir) = init_dir {
init_dir
} else if let Some(init_dir) =
Unit::try_new(pos12.translation.vector, crate::math::DEFAULT_EPSILON)
{
init_dir
} else {
Vector::x_axis()
};
simplex.reset(CSOPoint::from_shapes(pos12, g1, g2, &dir));
match gjk::closest_points(pos12, g1, g2, 0.0, false, simplex) {
GJKResult::Intersection => (true, dir),
GJKResult::Proximity(dir) => (false, dir),
GJKResult::NoIntersection(dir) => (false, dir),
GJKResult::ClosestPoints(..) => unreachable!(),
}
}