diff options
81 files changed, 421 insertions, 469 deletions
diff --git a/.github/workflows/rapier-ci-build.yml b/.github/workflows/rapier-ci-build.yml index 9328bc9..1b29d15 100644 --- a/.github/workflows/rapier-ci-build.yml +++ b/.github/workflows/rapier-ci-build.yml @@ -23,6 +23,12 @@ jobs: steps: - uses: actions/checkout@v3 - run: sudo apt-get install -y cmake libxcb-composite0-dev + - name: Clippy + run: cargo clippy + - name: Clippy rapier2d + run: cargo clippy -p rapier-examples-2d --features parallel,simd-stable + - name: Clippy rapier3d + run: cargo clippy -p rapier-examples-3d --features parallel,simd-stable - name: Build rapier2d run: cargo build --verbose -p rapier2d; - name: Build rapier3d diff --git a/benchmarks2d/all_benchmarks2.rs b/benchmarks2d/all_benchmarks2.rs index ce6aaac..fcc7b95 100644 --- a/benchmarks2d/all_benchmarks2.rs +++ b/benchmarks2d/all_benchmarks2.rs @@ -46,8 +46,8 @@ fn demo_name_from_url() -> Option<String> { #[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] pub fn main() { let demo = demo_name_from_command_line() - .or_else(|| demo_name_from_url()) - .unwrap_or(String::new()) + .or_else(demo_name_from_url) + .unwrap_or_default() .to_camel_case(); let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ @@ -66,7 +66,7 @@ pub fn main() { ]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with(')')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, diff --git a/benchmarks3d/all_benchmarks3.rs b/benchmarks3d/all_benchmarks3.rs index bca730b..591886e 100644 --- a/benchmarks3d/all_benchmarks3.rs +++ b/benchmarks3d/all_benchmarks3.rs @@ -36,7 +36,7 @@ fn parse_command_line() -> Command { while let Some(arg) = args.next() { if &arg[..] == "--example" { - return Command::Run(args.next().unwrap_or(String::new())); + return Command::Run(args.next().unwrap_or_default()); } else if &arg[..] == "--list" { return Command::List; } @@ -68,7 +68,7 @@ pub fn main() { ]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, diff --git a/benchmarks3d/keva3.rs b/benchmarks3d/keva3.rs index ecd6e77..4f5cd54 100644 --- a/benchmarks3d/keva3.rs +++ b/benchmarks3d/keva3.rs @@ -7,9 +7,7 @@ pub fn build_block( colliders: &mut ColliderSet, half_extents: Vector<f32>, shift: Vector<f32>, - mut numx: usize, - numy: usize, - mut numz: usize, + (mut numx, numy, mut numz): (usize, usize, usize), ) { let dimensions = [half_extents.xyz(), half_extents.zyx()]; let block_width = 2.0 * half_extents.z * numx as f32; @@ -56,8 +54,8 @@ pub fn build_block( // Close the top. let dim = half_extents.zxy(); - for i in 0..(block_width / (dim.x as f32 * 2.0)) as usize { - for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize { + for i in 0..(block_width / (dim.x * 2.0)) as usize { + for j in 0..(block_width / (dim.z * 2.0)) as usize { // Build the rigid body. let rigid_body = RigidBodyBuilder::dynamic().translation(vector![ i as f32 * dim.x * 2.0 + dim.x + shift.x, @@ -114,9 +112,7 @@ pub fn init_world(testbed: &mut Testbed) { &mut colliders, half_extents, vector![-block_width / 2.0, block_height, -block_width / 2.0], - numx, - numy, - numz, + (numx, numy, numz), ); block_height += numy as f32 * half_extents.y * 2.0 + half_extents.x * 2.0; num_blocks_built += numx * numy * numz; diff --git a/examples2d/all_examples2.rs b/examples2d/all_examples2.rs index 032e4d6..4cdbf98 100644 --- a/examples2d/all_examples2.rs +++ b/examples2d/all_examples2.rs @@ -57,8 +57,8 @@ fn demo_name_from_url() -> Option<String> { #[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] pub fn main() { let demo = demo_name_from_command_line() - .or_else(|| demo_name_from_url()) - .unwrap_or(String::new()) + .or_else(demo_name_from_url) + .unwrap_or_default() .to_camel_case(); let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ @@ -85,7 +85,7 @@ pub fn main() { ]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, diff --git a/examples2d/trimesh2.rs b/examples2d/trimesh2.rs index 219a583..2cb8410 100644 --- a/examples2d/trimesh2.rs +++ b/examples2d/trimesh2.rs @@ -104,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) { testbed.look_at(point![0.0, 20.0], 17.0); } -const RAPIER_SVG_STR: &'static str = r#" +const RAPIER_SVG_STR: &str = r#" <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100%" height="100%" viewBox="0 0 527 131" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:1.5;"> <g transform="matrix(1,0,0,1,1,-673)"> diff --git a/examples3d-f64/all_examples3-f64.rs b/examples3d-f64/all_examples3-f64.rs index 4464d60..c381eec 100644 --- a/examples3d-f64/all_examples3-f64.rs +++ b/examples3d-f64/all_examples3-f64.rs @@ -43,15 +43,15 @@ fn demo_name_from_url() -> Option<String> { #[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] pub fn main() { let demo = demo_name_from_command_line() - .or_else(|| demo_name_from_url()) - .unwrap_or(String::new()) + .or_else(demo_name_from_url) + .unwrap_or_default() .to_camel_case(); let mut builders: Vec<(_, fn(&mut Testbed))> = vec![("(Debug) serialized", debug_serialized3::init_world)]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, diff --git a/examples3d/all_examples3.rs b/examples3d/all_examples3.rs index 1bc8419..bac826e 100644 --- a/examples3d/all_examples3.rs +++ b/examples3d/all_examples3.rs @@ -86,8 +86,8 @@ fn demo_name_from_url() -> Option<String> { #[cfg_attr(target_arch = "wasm32", wasm_bindgen(start))] pub fn main() { let demo = demo_name_from_command_line() - .or_else(|| demo_name_from_url()) - .unwrap_or(String::new()) + .or_else(demo_name_from_url) + .unwrap_or_default() .to_camel_case(); let mut builders: Vec<(_, fn(&mut Testbed))> = vec![ @@ -157,7 +157,7 @@ pub fn main() { ]; // Lexicographic sort, with stress tests moved at the end of the list. - builders.sort_by(|a, b| match (a.0.starts_with("("), b.0.starts_with("(")) { + builders.sort_by(|a, b| match (a.0.starts_with('('), b.0.starts_with('(')) { (true, true) | (false, false) => a.0.cmp(b.0), (true, false) => Ordering::Greater, (false, true) => Ordering::Less, diff --git a/examples3d/ccd3.rs b/examples3d/ccd3.rs index 4047f4b..c1a5176 100644 --- a/examples3d/ccd3.rs +++ b/examples3d/ccd3.rs @@ -27,9 +27,9 @@ fn create_wall( colliders.insert_with_parent(collider, handle, bodies); k += 1; if k % 2 == 0 { - testbed.set_initial_body_color(handle, [255. / 255., 131. / 255., 244.0 / 255.]); + testbed.set_initial_body_color(handle, [1., 131. / 255., 244.0 / 255.]); } else { - testbed.set_initial_body_color(handle, [131. / 255., 255. / 255., 244.0 / 255.]); + testbed.set_initial_body_color(handle, [131. / 255., 1., 244.0 / 255.]); } } } diff --git a/examples3d/joints3.rs b/examples3d/joints3.rs index 18a11e7..73f48ae 100644 --- a/examples3d/joints3.rs +++ b/examples3d/joints3.rs @@ -482,7 +482,7 @@ fn create_actuated_revolute_joints( } else if i == num - 1 { let stiffness = 200.0; let damping = 100.0; - joint = joint.motor_position(3.14 / 2.0, stiffness, damping); + joint = joint.motor_position(std::f32::consts::FRAC_PI_2, stiffness, damping); } if i == 1 { @@ -541,7 +541,7 @@ fn create_actuated_spherical_joints( colliders.insert_with_parent(collider, child_handle, bodies); if i > 0 { - let mut joint = joint_template.clone(); + let mut joint = joint_template; if i == 1 { joint = joint @@ -554,7 +554,12 @@ fn create_actuated_spherical_joints( joint = joint .motor_position(JointAxis::AngX, 0.0, stiffness, damping) .motor_position(JointAxis::AngY, 1.0, stiffness, damping) - .motor_position(JointAxis::AngZ, 3.14 / 2.0, stiffness, damping); + .motor_position( + JointAxis::AngZ, + std::f32::consts::FRAC_PI_2, + stiffness, + damping, + ); } if use_articulations { diff --git a/examples3d/keva3.rs b/examples3d/keva3.rs index ecd6e77..4f5cd54 100644 --- a/examples3d/keva3.rs +++ b/examples3d/keva3.rs @@ -7,9 +7,7 @@ pub fn build_block( colliders: &mut ColliderSet, half_extents: Vector<f32>, shift: Vector<f32>, - mut numx: usize, - numy: usize, - mut numz: usize, + (mut numx, numy, mut numz): (usize, usize, usize), ) { let dimensions = [half_extents.xyz(), half_extents.zyx()]; let block_width = 2.0 * half_extents.z * numx as f32; @@ -56,8 +54,8 @@ pub fn build_block( // Close the top. let dim = half_extents.zxy(); - for i in 0..(block_width / (dim.x as f32 * 2.0)) as usize { - for j in 0..(block_width / (dim.z as f32 * 2.0)) as usize { + for i in 0..(block_width / (dim.x * 2.0)) as usize { + for j in 0..(block_width / (dim.z * 2.0)) as usize { // Build the rigid body. let rigid_body = RigidBodyBuilder::dynamic().translation(vector![ i as f32 * dim.x * 2.0 + dim.x + shift.x, @@ -114,9 +112,7 @@ pub fn init_world(testbed: &mut Testbed) { &mut colliders, half_extents, vector![-block_width / 2.0, block_height, -block_width / 2.0], - numx, - numy, - numz, + (numx, numy, numz), ); block_height += numy as f32 * half_extents.y * 2.0 + half_extents.x * 2.0; num_blocks_built += numx * numy * numz; diff --git a/examples3d/rope_joints3.rs b/examples3d/rope_joints3.rs index 9696682..11f0716 100644 --- a/examples3d/rope_joints3.rs +++ b/examples3d/rope_joints3.rs @@ -67,7 +67,7 @@ pub fn init_world(testbed: &mut Testbed) { let collider = ColliderBuilder::cuboid(0.15, 0.3, 0.15); colliders.insert_with_parent(collider, character_handle, &mut bodies); - testbed.set_initial_body_color(character_handle, [255. / 255., 131. / 255., 244.0 / 255.]); + testbed.set_initial_body_color(character_handle, [1., 131. / 255., 244.0 / 255.]); /* * Tethered Ball diff --git a/examples3d/vehicle_controller3.rs b/examples3d/vehicle_controller3.rs index 1228c82..846d9fe 100644 --- a/examples3d/vehicle_controller3.rs +++ b/examples3d/vehicle_controller3.rs @@ -32,9 +32,11 @@ pub fn init_world(testbed: &mut Testbed) { let collider = ColliderBuilder::cuboid(hw * 2.0, hh, hw).density(100.0); colliders.insert_with_parent(collider, vehicle_handle, &mut bodies); - let mut tuning = WheelTuning::default(); - tuning.suspension_stiffness = 100.0; - tuning.suspension_damping = 10.0; + let tuning = WheelTuning { + suspension_stiffness: 100.0, + suspension_damping: 10.0, + ..WheelTuning::default() + }; let mut vehicle = DynamicRayCastVehicleController::new(vehicle_handle); let wheel_positions = [ point![hw * 1.5, -hh, hw], diff --git a/src/control/ray_cast_vehicle_controller.rs b/src/control/ray_cast_vehicle_controller.rs index 30979e1..00b11eb 100644 --- a/src/control/ray_cast_vehicle_controller.rs +++ b/src/control/ray_cast_vehicle_controller.rs @@ -582,7 +582,7 @@ impl DynamicRayCastVehicleController { wheel.side_impulse = resolve_single_bilateral( &bodies[self.chassis], &wheel.raycast_info.contact_point_ws, - &ground_body, + ground_body, &wheel.raycast_info.contact_point_ws, &self.axle[i], ); @@ -664,11 +664,9 @@ impl DynamicRayCastVehicleController { if sliding { for wheel in &mut self.wheels { - if wheel.side_impulse != 0.0 { - if wheel.skid_info < 1.0 { - wheel.forward_impulse *= wheel.skid_info; - wheel.side_impulse *= wheel.skid_info; - } + if wheel.side_impulse != 0.0 && wheel.skid_info < 1.0 { + wheel.forward_impulse *= wheel.skid_info; + wheel.side_impulse *= wheel.skid_info; } } } diff --git a/src/data/arena.rs b/src/data/arena.rs index 3332539..57653da 100644 --- a/src/data/arena.rs +++ b/src/data/arena.rs @@ -269,7 +26 |
