rapier3d/geometry/
broad_phase_pair_event.rs

1use crate::geometry::ColliderHandle;
2
3#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
4#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
5/// A pair of collider handles.
6pub struct ColliderPair {
7    /// The handle of the first collider involved in this pair.
8    pub collider1: ColliderHandle,
9    /// The handle of the second ocllider involved in this pair.
10    pub collider2: ColliderHandle,
11}
12
13impl ColliderPair {
14    /// Creates a new pair of collider handles.
15    pub fn new(collider1: ColliderHandle, collider2: ColliderHandle) -> Self {
16        ColliderPair {
17            collider1,
18            collider2,
19        }
20    }
21
22    /// Swaps the two collider handles in `self`.
23    pub fn swap(self) -> Self {
24        Self::new(self.collider2, self.collider1)
25    }
26
27    /// Constructs a pair of artificial handles that are not guaranteed to be valid..
28    pub fn zero() -> Self {
29        Self {
30            collider1: ColliderHandle::from_raw_parts(0, 0),
31            collider2: ColliderHandle::from_raw_parts(0, 0),
32        }
33    }
34}
35
36impl Default for ColliderPair {
37    fn default() -> Self {
38        ColliderPair::zero()
39    }
40}
41
42/// An event emitted by the broad-phase.
43pub enum BroadPhasePairEvent {
44    /// A potential new collision pair has been detected by the broad-phase.
45    AddPair(ColliderPair),
46    /// The two colliders are guaranteed not to touch any more.
47    DeletePair(ColliderPair),
48}