parry3d/query/intersection_test/
intersection_test_composite_shape_shape.rs1use crate::bounding_volume::BoundingVolume;
2use crate::math::{Isometry, Real};
3use crate::partitioning::BvhNode;
4use crate::query::QueryDispatcher;
5use crate::shape::{CompositeShapeRef, Shape, TypedCompositeShape};
6use crate::utils::IsometryOpt;
7
8impl<S: ?Sized + TypedCompositeShape> CompositeShapeRef<'_, S> {
9 pub fn intersects_shape<D: ?Sized + QueryDispatcher>(
14 &self,
15 dispatcher: &D,
16 pose12: &Isometry<Real>,
17 shape: &dyn Shape,
18 ) -> Option<u32> {
19 let ls_aabb2 = shape.compute_aabb(pose12);
20 self.0
21 .bvh()
22 .leaves(|node: &BvhNode| node.aabb().intersects(&ls_aabb2))
23 .find(|leaf_id| {
24 self.0
25 .map_untyped_part_at(*leaf_id, |part_pose1, sub1, _| {
26 dispatcher.intersection_test(&part_pose1.inv_mul(pose12), sub1, shape)
27 == Ok(true)
28 })
29 .unwrap_or(false)
30 })
31 }
32}
33
34pub fn intersection_test_composite_shape_shape<D, G1>(
36 dispatcher: &D,
37 pos12: &Isometry<Real>,
38 g1: &G1,
39 g2: &dyn Shape,
40) -> bool
41where
42 D: ?Sized + QueryDispatcher,
43 G1: ?Sized + TypedCompositeShape,
44{
45 CompositeShapeRef(g1)
46 .intersects_shape(dispatcher, pos12, g2)
47 .is_some()
48}
49
50pub fn intersection_test_shape_composite_shape<D, G2>(
52 dispatcher: &D,
53 pos12: &Isometry<Real>,
54 g1: &dyn Shape,
55 g2: &G2,
56) -> bool
57where
58 D: ?Sized + QueryDispatcher,
59 G2: ?Sized + TypedCompositeShape,
60{
61 intersection_test_composite_shape_shape(dispatcher, &pos12.inverse(), g2, g1)
62}