ncollide3d/pipeline/broad_phase/
broad_phase.rs
1use na::RealField;
2use std::any::Any;
3
4use crate::math::Point;
5use crate::query::{Ray, RayIntersection};
6
7#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
8pub struct BroadPhaseProxyHandle(pub usize);
9
10impl BroadPhaseProxyHandle {
11 #[inline]
12 pub fn invalid() -> Self {
13 BroadPhaseProxyHandle(usize::max_value())
14 }
15
16 #[inline]
17 pub fn is_invalid(&self) -> bool {
18 self.0 == usize::max_value()
19 }
20
21 #[inline]
22 pub fn uid(&self) -> usize {
23 self.0
24 }
25}
26
27pub trait BroadPhaseInterferenceHandler<T> {
29 fn is_interference_allowed(&mut self, data1: &T, data2: &T) -> bool;
32
33 fn interference_started(&mut self, data1: &T, data2: &T);
35
36 fn interference_stopped(&mut self, data1: &T, data2: &T);
38}
39
40pub trait BroadPhase<N: RealField + Copy, BV, T>: Any + Sync + Send {
42 fn create_proxy(&mut self, bv: BV, data: T) -> BroadPhaseProxyHandle;
44
45 fn proxy(&self, handle: BroadPhaseProxyHandle) -> Option<(&BV, &T)>;
47
48 fn remove(
50 &mut self,
51 handles: &[BroadPhaseProxyHandle],
52 removal_handler: &mut dyn FnMut(&T, &T),
53 );
54
55 fn deferred_set_bounding_volume(&mut self, handle: BroadPhaseProxyHandle, bv: BV);
57
58 fn deferred_recompute_all_proximities_with(&mut self, handle: BroadPhaseProxyHandle);
60
61 fn deferred_recompute_all_proximities(&mut self);
63
64 fn update(&mut self, handler: &mut dyn BroadPhaseInterferenceHandler<T>);
66
67 fn interferences_with_bounding_volume<'a>(&'a self, bv: &BV, out: &mut Vec<&'a T>);
73
74 fn interferences_with_ray<'a>(&'a self, ray: &Ray<N>, max_toi: N, out: &mut Vec<&'a T>);
76
77 fn interferences_with_point<'a>(&'a self, point: &Point<N>, out: &mut Vec<&'a T>);
79
80 fn first_interference_with_ray<'a, 'b>(
81 &'a self,
82 ray: &'b Ray<N>,
83 max_toi: N,
84 cost_fn: &'a dyn Fn(T, &'b Ray<N>, N) -> Option<(T, RayIntersection<N>)>,
85 ) -> Option<(T, RayIntersection<N>)>;
86}