parry3d/query/intersection_test/
intersection_test_cuboid_segment.rs

1use crate::bounding_volume::Aabb;
2use crate::math::{Isometry, Real};
3use crate::query::sat;
4use crate::shape::{Cuboid, Segment};
5
6/// Test if a segment intersects an Aabb.
7pub fn intersection_test_aabb_segment(aabb1: &Aabb, segment2: &Segment) -> 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_segment(&pos12, &cuboid1, segment2)
11}
12
13/// Test if a segment intersects a cuboid.
14#[inline]
15pub fn intersection_test_segment_cuboid(
16    pos12: &Isometry<Real>,
17    segment1: &Segment,
18    cuboid2: &Cuboid,
19) -> bool {
20    intersection_test_cuboid_segment(&pos12.inverse(), cuboid2, segment1)
21}
22
23/// Test if a segment intersects a cuboid.
24#[inline]
25pub fn intersection_test_cuboid_segment(
26    pos12: &Isometry<Real>,
27    cube1: &Cuboid,
28    segment2: &Segment,
29) -> bool {
30    let sep1 =
31        sat::cuboid_support_map_find_local_separating_normal_oneway(cube1, segment2, pos12).0;
32    if sep1 > 0.0 {
33        return false;
34    }
35
36    // This case does not exist in 3D.
37    #[cfg(feature = "dim2")]
38    {
39        let sep2 = sat::segment_cuboid_find_local_separating_normal_oneway(
40            segment2,
41            cube1,
42            &pos12.inverse(),
43        )
44        .0;
45        if sep2 > 0.0 {
46            return false;
47        }
48    }
49
50    #[cfg(feature = "dim2")]
51    return true; // This case does not exist in 2D.
52    #[cfg(feature = "dim3")]
53    {
54        let sep3 = sat::cuboid_segment_find_local_separating_edge_twoway(cube1, segment2, pos12).0;
55        sep3 <= 0.0
56    }
57}