ncollide3d/query/visitors/
point_interferences_collector.rs

1use crate::math::{Isometry, Point};
2use crate::partitioning::{VisitStatus, Visitor};
3use crate::query::PointQuery;
4use na::RealField;
5
6// FIXME: add a point cost fn.
7
8/// Spatial partitioning structure visitor collecting nodes that may contain a given point.
9pub struct PointInterferencesCollector<'a, N: 'a + RealField + Copy, T: 'a> {
10    /// Point to be tested.
11    pub point: &'a Point<N>,
12    /// The data contained by the nodes which bounding volume contain `self.point`.
13    pub collector: &'a mut Vec<T>,
14}
15
16impl<'a, N: RealField + Copy, T> PointInterferencesCollector<'a, N, T> {
17    /// Creates a new `PointInterferencesCollector`.
18    #[inline]
19    pub fn new(
20        point: &'a Point<N>,
21        buffer: &'a mut Vec<T>,
22    ) -> PointInterferencesCollector<'a, N, T> {
23        PointInterferencesCollector {
24            point: point,
25            collector: buffer,
26        }
27    }
28}
29
30impl<'a, N, T, BV> Visitor<T, BV> for PointInterferencesCollector<'a, N, T>
31where
32    N: RealField + Copy,
33    T: Clone,
34    BV: PointQuery<N>,
35{
36    #[inline]
37    fn visit(&mut self, bv: &BV, t: Option<&T>) -> VisitStatus {
38        if bv.contains_point(&Isometry::identity(), self.point) {
39            if let Some(t) = t {
40                self.collector.push(t.clone());
41            }
42            VisitStatus::Continue
43        } else {
44            VisitStatus::Stop
45        }
46    }
47}