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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
pub use collision::algorithm::broad_phase::*;
use collision::prelude::*;
use super::{CollisionData, GetId};
pub trait BroadPhase<A>: Send
where
A: HasBound,
{
fn find_potentials(&mut self, shapes: &mut [A]) -> Vec<(usize, usize)>;
}
impl<A> BroadPhase<A> for BruteForce
where
A: HasBound,
A::Bound: Discrete<A::Bound>,
{
fn find_potentials(&mut self, shapes: &mut [A]) -> Vec<(usize, usize)> {
self.find_collider_pairs(shapes)
}
}
impl<A, V> BroadPhase<A> for SweepAndPrune<V>
where
A: HasBound,
A::Bound: Discrete<A::Bound>,
V: Variance<Bound = A::Bound> + Send,
{
fn find_potentials(&mut self, shapes: &mut [A]) -> Vec<(usize, usize)> {
self.find_collider_pairs(shapes)
}
}
pub fn broad_collide<C, I, P, T, B, Y, D>(data: &C, broad: &mut Box<BroadPhase<D>>) -> Vec<(I, I)>
where
C: CollisionData<I, P, T, B, Y, D>,
P: Primitive,
D: HasBound<Bound = B> + GetId<I>,
B: Bound<Point = P::Point>,
{
let mut info = data.get_broad_data();
broad
.find_potentials(&mut info)
.iter()
.map(|&(a, b)| (info[a].id(), info[b].id()))
.collect::<Vec<_>>()
}