aboutsummaryrefslogtreecommitdiff
path: root/src/utils.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2021-04-01 11:00:27 +0200
committerGitHub <noreply@github.com>2021-04-01 11:00:27 +0200
commitf8536e73fc092da5ded5c793d513c59296949aff (patch)
tree50af9e4312b22ea2c1cabc0e6d80dc73e59b3104 /src/utils.rs
parent4b637c66ca40695f97f1ebdc38965e0d83ac5934 (diff)
parentcc3f16eb85f23a86ddd9d182d967cb12acc32354 (diff)
downloadrapier-f8536e73fc092da5ded5c793d513c59296949aff.tar.gz
rapier-f8536e73fc092da5ded5c793d513c59296949aff.tar.bz2
rapier-f8536e73fc092da5ded5c793d513c59296949aff.zip
Merge pull request #157 from dimforge/ccd
Implement Continuous Collision Detection
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 4ed89f6..c1eb31d 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -3,6 +3,7 @@
use na::{Matrix3, Point2, Point3, Scalar, SimdRealField, Vector2, Vector3};
use num::Zero;
use simba::simd::SimdValue;
+use std::ops::IndexMut;
use parry::utils::SdpMatrix3;
use {
@@ -676,3 +677,34 @@ pub(crate) fn select_other<T: PartialEq>(pair: (T, T), elt: T) -> T {
pair.0
}
}
+
+/// Methods for simultaneously indexing a container with two distinct indices.
+pub trait IndexMut2<I>: IndexMut<I> {
+ /// Gets mutable references to two distinct elements of the container.
+ ///
+ /// Panics if `i == j`.
+ fn index_mut2(&mut self, i: usize, j: usize) -> (&mut Self::Output, &mut Self::Output);
+
+ /// Gets a mutable reference to one element, and immutable reference to a second one.
+ ///
+ /// Panics if `i == j`.
+ #[inline]
+ fn index_mut_const(&mut self, i: usize, j: usize) -> (&mut Self::Output, &Self::Output) {
+ let (a, b) = self.index_mut2(i, j);
+ (a, &*b)
+ }
+}
+
+impl<T> IndexMut2<usize> for Vec<T> {
+ #[inline]
+ fn index_mut2(&mut self, i: usize, j: usize) -> (&mut T, &mut T) {
+ assert!(i != j, "Unable to index the same element twice.");
+ assert!(i < self.len() && j < self.len(), "Index out of bounds.");
+
+ unsafe {
+ let a = &mut *(self.get_unchecked_mut(i) as *mut _);
+ let b = &mut *(self.get_unchecked_mut(j) as *mut _);
+ (a, b)
+ }
+ }
+}