aboutsummaryrefslogtreecommitdiff
path: root/src/data/coarena.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-01-02 14:47:40 +0100
committerSébastien Crozet <developer@crozet.re>2022-01-02 16:58:36 +0100
commitf74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc (patch)
tree53ac492fea5942a7d466f58a0095f39505674ea4 /src/data/coarena.rs
parentb45d4b5ac2b31856c15e802b31e288a58940cbf2 (diff)
downloadrapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.tar.gz
rapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.tar.bz2
rapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.zip
Implement multibody joints and the new solver
Diffstat (limited to 'src/data/coarena.rs')
-rw-r--r--src/data/coarena.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/data/coarena.rs b/src/data/coarena.rs
index 124d85a..1f01c05 100644
--- a/src/data/coarena.rs
+++ b/src/data/coarena.rs
@@ -13,6 +13,14 @@ impl<T> Coarena<T> {
Self { data: Vec::new() }
}
+ pub fn iter(&self) -> impl Iterator<Item = (Index, &T)> {
+ self.data
+ .iter()
+ .enumerate()
+ .filter(|(_, elt)| elt.0 != u32::MAX)
+ .map(|(i, elt)| (Index::from_raw_parts(i as u32, elt.0), &elt.1))
+ }
+
/// Gets a specific element from the coarena without specifying its generation number.
///
/// It is strongly encouraged to use `Coarena::get` instead of this method because this method
@@ -23,12 +31,12 @@ impl<T> Coarena<T> {
/// Deletes an element for the coarena and returns its value.
///
- /// We can't really remove an element from the coarena. So instead of actually removing
- /// it, this method will reset the value to the given `removed_value`.
+ /// This method will reset the value to the given `removed_value`.
pub fn remove(&mut self, index: Index, removed_value: T) -> Option<T> {
let (i, g) = index.into_raw_parts();
let data = self.data.get_mut(i as usize)?;
if g == data.0 {
+ data.0 = u32::MAX; // invalidate the generation number.
Some(std::mem::replace(&mut data.1, removed_value))
} else {
None