use glam_det::{UnitQuat, Vec3};
use super::traits::*;
use crate::shapes::ConvexHull;
use crate::{Shape, ShapeContainer, ShapeRef};
macro_rules! impl_overlap_tests {
($(($query_name:ident, $hit_name:ident)),*) => {
#[allow(unreachable_patterns)]
#[inline]
fn overlap_impl(
query_shape: &ShapeRef,
hit_shape: &ShapeRef,
offset_b: Vec3,
orientation_a: UnitQuat,
orientation_b: UnitQuat,
) -> bool {
match (&query_shape.value, &hit_shape.value) {
(Shape::ConvexHull(_), _) => {
todo!("issue #1201")
}
(query_shape_enum, Shape::ConvexHull(hit_convex_hull_id)) => {
match query_shape_enum {
Shape::Cuboid(query_shape) => {
let convex_hull = hit_shape.container.get::<ConvexHull>(*hit_convex_hull_id)
.expect("fail to map ConvexHullId to ConvexHull");
query_shape.overlap_test(convex_hull, offset_b, orientation_a, orientation_b,None)
}
Shape::Sphere(query_shape) => {
let convex_hull = hit_shape.container.get::<ConvexHull>(*hit_convex_hull_id)
.expect("fail to map ConvexHullId to ConvexHull");
query_shape.overlap_test(convex_hull, offset_b, orientation_a, orientation_b,None)
}
Shape::Capsule(query_shape) => {
let convex_hull = hit_shape.container.get::<ConvexHull>(*hit_convex_hull_id)
.expect("fail to map ConvexHullId to ConvexHull");
query_shape.overlap_test(convex_hull, offset_b, orientation_a, orientation_b,None)
}
_ => todo!("other shape overlap convex, issue #1201")
}
}
$(
(Shape::$query_name(query_shape), Shape::$hit_name(hit_shape)) => {
query_shape.overlap_test(hit_shape, offset_b, orientation_a,orientation_b,None)
}
)*
_=>false
}
}
};
}
impl_overlap_tests!(
(Sphere, Sphere),
(Sphere, Capsule),
(Sphere, Cuboid),
(Sphere, Cylinder),
(Sphere, InfinitePlane),
(Cuboid, Cuboid),
(Cuboid, Capsule),
(Cuboid, Sphere),
(Cuboid, Cylinder),
(Cuboid, InfinitePlane),
(Capsule, Cuboid),
(Capsule, Capsule),
(Capsule, Sphere),
(Capsule, Cylinder),
(Capsule, InfinitePlane)
);
#[must_use]
pub fn overlap(
query_shape: &ShapeRef,
hit_shape: &ShapeRef,
offset_b: Vec3,
orientation_a: UnitQuat,
orientation_b: UnitQuat,
_: Option<&ShapeContainer>,
) -> bool {
overlap_impl(
query_shape,
hit_shape,
offset_b,
orientation_a,
orientation_b,
)
}