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