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