parry3d/query/intersection_test/
intersection_test_cuboid_triangle.rs

1use crate::bounding_volume::Aabb;
2use crate::math::{Isometry, Real};
3use crate::query::sat;
4use crate::shape::{Cuboid, Triangle};
5
6/// Tests if a triangle intersects an Aabb.
7pub fn intersection_test_aabb_triangle(aabb1: &Aabb, triangle2: &Triangle) -> bool {
8    let cuboid1 = Cuboid::new(aabb1.half_extents());
9    let pos12 = Isometry::from_parts((-aabb1.center().coords).into(), na::one());
10    intersection_test_cuboid_triangle(&pos12, &cuboid1, triangle2)
11}
12
13/// Tests if a triangle intersects a cuboid.
14#[inline]
15pub fn intersection_test_triangle_cuboid(
16    pos12: &Isometry<Real>,
17    triangle1: &Triangle,
18    cuboid2: &Cuboid,
19) -> bool {
20    intersection_test_cuboid_triangle(&pos12.inverse(), cuboid2, triangle1)
21}
22
23/// Tests if a triangle intersects an cuboid.
24#[inline]
25pub fn intersection_test_cuboid_triangle(
26    pos12: &Isometry<Real>,
27    cube1: &Cuboid,
28    triangle2: &Triangle,
29) -> bool {
30    let sep1 =
31        sat::cuboid_support_map_find_local_separating_normal_oneway(cube1, triangle2, pos12).0;
32    if sep1 > 0.0 {
33        return false;
34    }
35
36    let pos21 = pos12.inverse();
37    let sep2 = sat::triangle_cuboid_find_local_separating_normal_oneway(triangle2, cube1, &pos21).0;
38    if sep2 > 0.0 {
39        return false;
40    }
41
42    #[cfg(feature = "dim2")]
43    return true; // This case does not exist in 2D.
44    #[cfg(feature = "dim3")]
45    {
46        let sep3 =
47            sat::cuboid_triangle_find_local_separating_edge_twoway(cube1, triangle2, pos12).0;
48        sep3 <= 0.0
49    }
50}