ncollide3d/query/visitors/
composite_point_containment_test.rs

1use crate::bounding_volume::BoundingVolume;
2use crate::math::{Isometry, Point};
3use crate::partitioning::{VisitStatus, Visitor};
4use crate::query::PointQuery;
5use crate::shape::CompositeShape;
6use na::RealField;
7
8/// Visitor for checking if a composite shape contains a specific point.
9pub struct CompositePointContainmentTest<'a, N: 'a + RealField + Copy, S: 'a + CompositeShape<N>> {
10    /// The composite shape on which the point containment test should be performed.
11    pub shape: &'a S,
12    /// The point to be tested.
13    pub point: &'a Point<N>,
14    /// A traversal will set this to `true` if the point is inside of `self.shape`.
15    pub found: bool,
16}
17
18impl<'a, N: RealField + Copy, BV: BoundingVolume<N> + PointQuery<N>, S: CompositeShape<N>>
19    Visitor<usize, BV> for CompositePointContainmentTest<'a, N, S>
20{
21    #[inline]
22    fn visit(&mut self, bv: &BV, b: Option<&usize>) -> VisitStatus {
23        if bv.contains_point(&Isometry::identity(), self.point) {
24            if let Some(b) = b {
25                self.shape
26                    .map_part_at(*b, &Isometry::identity(), &mut |objm, obj| {
27                        if obj.contains_point(objm, self.point) {
28                            self.found = true;
29                        }
30                    })
31            }
32
33            if self.found {
34                VisitStatus::ExitEarly
35            } else {
36                VisitStatus::Continue
37            }
38        } else {
39            VisitStatus::Stop
40        }
41    }
42}