From 437748096d96d4bde5540711580be26a2b146b65 Mon Sep 17 00:00:00 2001 From: Crozet Sébastien Date: Tue, 24 Nov 2020 15:21:27 +0100 Subject: Allow retrieving one specific contact pair or proximity pair. --- src/geometry/narrow_phase.rs | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/geometry/narrow_phase.rs b/src/geometry/narrow_phase.rs index cf7b531..a3d0ea7 100644 --- a/src/geometry/narrow_phase.rs +++ b/src/geometry/narrow_phase.rs @@ -106,14 +106,39 @@ impl NarrowPhase { ) } - // #[cfg(feature = "parallel")] - // pub fn contact_pairs(&self) -> &[ContactPair] { - // &self.contact_graph.interactions - // } + /// The contact pair involving two specific colliders. + /// + /// If this returns `None`, there is no contact between the two colliders. + /// If this returns `Some`, then there may be a contact between the two colliders. Check the + /// result [`ContactPair::has_any_active_collider`] method to see if there is an actual contact. + pub fn contact_pair( + &self, + collider1: ColliderHandle, + collider2: ColliderHandle, + ) -> Option<&ContactPair> { + let id1 = self.graph_indices.get(collider1)?; + let id2 = self.graph_indices.get(collider2)?; + self.contact_graph + .interaction_pair(id1.contact_graph_index, id2.contact_graph_index) + .map(|c| c.2) + } - // pub fn contact_pairs_mut(&mut self) -> &mut [ContactPair] { - // &mut self.contact_graph.interactions - // } + /// The proximity pair involving two specific colliders. + /// + /// If this returns `None`, there is no intersection between the two colliders. + /// If this returns `Some`, then there may be an intersection between the two colliders. Check the + /// value of [`ProximityPair::proximity`] method to see if there is an actual intersection. + pub fn proximity_pair( + &self, + collider1: ColliderHandle, + collider2: ColliderHandle, + ) -> Option<&ProximityPair> { + let id1 = self.graph_indices.get(collider1)?; + let id2 = self.graph_indices.get(collider2)?; + self.proximity_graph + .interaction_pair(id1.proximity_graph_index, id2.proximity_graph_index) + .map(|c| c.2) + } // #[cfg(feature = "parallel")] // pub(crate) fn contact_pairs_vec_mut(&mut self) -> &mut Vec { -- cgit