diff options
| author | Sébastien Crozet <sebcrozet@dimforge.com> | 2024-07-06 18:28:40 +0200 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2024-07-07 15:22:55 +0200 |
| commit | 40ee5367d89bd624cb4e01fbd304de494564ebd6 (patch) | |
| tree | 492a89652ef52d334a35c5d13e277969d48e748f /src | |
| parent | de82bea9c04139d4c0f97cc79de02069a37b9ef1 (diff) | |
| download | rapier-40ee5367d89bd624cb4e01fbd304de494564ebd6.tar.gz rapier-40ee5367d89bd624cb4e01fbd304de494564ebd6.tar.bz2 rapier-40ee5367d89bd624cb4e01fbd304de494564ebd6.zip | |
chore: add one more test for the multibody insertion out-of-bounds issue
Diffstat (limited to 'src')
| -rw-r--r-- | src/dynamics/joint/multibody_joint/multibody.rs | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/dynamics/joint/multibody_joint/multibody.rs b/src/dynamics/joint/multibody_joint/multibody.rs index 6c8344b..7832abe 100644 --- a/src/dynamics/joint/multibody_joint/multibody.rs +++ b/src/dynamics/joint/multibody_joint/multibody.rs @@ -1374,7 +1374,8 @@ mod test { use crate::dynamics::{ImpulseJointSet, IslandManager}; use crate::math::{Real, SPATIAL_DIM}; use crate::prelude::{ - ColliderSet, MultibodyJointSet, RevoluteJoint, RigidBodyBuilder, RigidBodySet, + ColliderSet, MultibodyJointHandle, MultibodyJointSet, RevoluteJoint, RigidBodyBuilder, + RigidBodySet, }; use na::{DVector, RowDVector}; @@ -1401,6 +1402,57 @@ mod test { } #[test] + fn test_multibody_insert() { + let mut rnd = oorandom::Rand32::new(1234); + + for k in 0..10 { + let mut bodies = RigidBodySet::new(); + let mut multibody_joints = MultibodyJointSet::new(); + + let num_links = 100; + let mut handles = vec![]; + + for _ in 0..num_links { + handles.push(bodies.insert(RigidBodyBuilder::dynamic())); + } + + let mut insertion_id: Vec<_> = (0..num_links - 1).collect(); + + #[cfg(feature = "dim2")] + let joint = RevoluteJoint::new(); + #[cfg(feature = "dim3")] + let joint = RevoluteJoint::new(na::Vector::x_axis()); + + match k { + 0 => {} // Remove in insertion order. + 1 => { + // Remove from leaf to root. + insertion_id.reverse(); + } + _ => { + // Shuffle the vector a bit. + // (This test checks multiple shuffle arrangements due to k > 2). + for l in 0..num_links - 1 { + insertion_id.swap(l, rnd.rand_range(0..num_links as u32 - 1) as usize); + } + } + } + + let mut mb_handle = MultibodyJointHandle::invalid(); + for i in insertion_id { + mb_handle = multibody_joints + .insert(handles[i], handles[i + 1], joint, true) + .unwrap(); + } + + assert_eq!( + multibody_joints.get(mb_handle).unwrap().0.ndofs, + SPATIAL_DIM + num_links - 1 + ); + } + } + + #[test] fn test_multibody_remove() { let mut rnd = oorandom::Rand32::new(1234); |
