ncollide3d/query/visitors/
ray_interferences_collector.rs
1use crate::math::Isometry;
2use crate::partitioning::{VisitStatus, Visitor};
3use crate::query::{Ray, RayCast};
4use na::RealField;
5
6pub struct RayInterferencesCollector<'a, N: 'a + RealField + Copy, T: 'a> {
8 pub ray: &'a Ray<N>,
10 pub max_toi: N,
12 pub collector: &'a mut Vec<T>,
14}
15
16impl<'a, N: RealField + Copy, T> RayInterferencesCollector<'a, N, T> {
17 #[inline]
19 pub fn new(
20 ray: &'a Ray<N>,
21 max_toi: N,
22 buffer: &'a mut Vec<T>,
23 ) -> RayInterferencesCollector<'a, N, T> {
24 RayInterferencesCollector {
25 ray,
26 max_toi,
27 collector: buffer,
28 }
29 }
30}
31
32impl<'a, N, T, BV> Visitor<T, BV> for RayInterferencesCollector<'a, N, T>
33where
34 N: RealField + Copy,
35 T: Clone,
36 BV: RayCast<N>,
37{
38 #[inline]
39 fn visit(&mut self, bv: &BV, t: Option<&T>) -> VisitStatus {
40 if bv.intersects_ray(&Isometry::identity(), self.ray, self.max_toi) {
41 if let Some(t) = t {
42 self.collector.push(t.clone())
43 }
44
45 VisitStatus::Continue
46 } else {
47 VisitStatus::Stop
48 }
49 }
50}