Skip to content

Commit

Permalink
Fix clippy and enable clippy on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Jan 27, 2024
1 parent aef873f commit da92e5c
Show file tree
Hide file tree
Showing 81 changed files with 421 additions and 469 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/rapier-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions benchmarks2d/all_benchmarks2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions benchmarks3d/all_benchmarks3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions benchmarks3d/keva3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions examples2d/all_examples2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion examples2d/trimesh2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)">
Expand Down
6 changes: 3 additions & 3 deletions examples3d-f64/all_examples3-f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples3d/all_examples3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions examples3d/ccd3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.]);
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions examples3d/joints3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions examples3d/keva3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples3d/rope_joints3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions examples3d/vehicle_controller3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
10 changes: 4 additions & 6 deletions src/control/ray_cast_vehicle_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
);
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<T> Arena<T> {
self.free_list_head = next_free;
self.len += 1;
Some(Index {
index: i as u32,
index: i,
generation: self.generation,
})
}
Expand Down
3 changes: 1 addition & 2 deletions src/data/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ impl<T> PubSub<T> {
/// Read the i-th message not yet read by the given subsciber.
pub fn read_ith(&self, sub: &Subscription<T>, i: usize) -> Option<&T> {
let cursor = &self.cursors[sub.id as usize];
self.messages
.get(cursor.next(self.deleted_messages) as usize + i)
self.messages.get(cursor.next(self.deleted_messages) + i)
}

/// Get the messages not yet read by the given subscriber.
Expand Down
45 changes: 20 additions & 25 deletions src/dynamics/ccd/ccd_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,27 @@ impl CCDSolver {
///
/// The `impacts` should be the result of a previous call to `self.predict_next_impacts`.
pub fn clamp_motions(&self, dt: Real, bodies: &mut RigidBodySet, impacts: &PredictedImpacts) {
match impacts {
PredictedImpacts::Impacts(tois) => {
for (handle, toi) in tois {
let rb = bodies.index_mut_internal(*handle);
let local_com = &rb.mprops.local_mprops.local_com;

let min_toi = (rb.ccd.ccd_thickness
* 0.15
* crate::utils::inv(rb.ccd.max_point_velocity(&rb.integrated_vels)))
.min(dt);
// println!(
// "Min toi: {}, Toi: {}, thick: {}, max_vel: {}",
// min_toi,
// toi,
// rb.ccd.ccd_thickness,
// rb.ccd.max_point_velocity(&rb.integrated_vels)
// );
let new_pos = rb.integrated_vels.integrate(
toi.max(min_toi),
&rb.pos.position,
&local_com,
);
rb.pos.next_position = new_pos;
}
if let PredictedImpacts::Impacts(tois) = impacts {
for (handle, toi) in tois {
let rb = bodies.index_mut_internal(*handle);
let local_com = &rb.mprops.local_mprops.local_com;

let min_toi = (rb.ccd.ccd_thickness
* 0.15
* crate::utils::inv(rb.ccd.max_point_velocity(&rb.integrated_vels)))
.min(dt);
// println!(
// "Min toi: {}, Toi: {}, thick: {}, max_vel: {}",
// min_toi,
// toi,
// rb.ccd.ccd_thickness,
// rb.ccd.max_point_velocity(&rb.integrated_vels)
// );
let new_pos =
rb.integrated_vels
.integrate(toi.max(min_toi), &rb.pos.position, local_com);
rb.pos.next_position = new_pos;
}
_ => {}
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/dynamics/ccd/toi_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,15 @@ impl TOIEntry {

impl PartialOrd for TOIEntry {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
(-self.toi).partial_cmp(&(-other.toi))
Some(self.cmp(other))
}
}

impl Ord for TOIEntry {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.partial_cmp(other).unwrap()
(-self.toi)
.partial_cmp(&(-other.toi))
.unwrap_or(std::cmp::Ordering::Equal)
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/dynamics/coefficient_combine_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use crate::math::Real;
/// Each collider has its combination rule of type
/// `CoefficientCombineRule`. And the rule
/// actually used is given by `max(first_combine_rule as usize, second_combine_rule as usize)`.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
pub enum CoefficientCombineRule {
/// The two coefficients are averaged.
#[default]
Average = 0,
/// The smallest coefficient is chosen.
Min,
Expand All @@ -20,12 +21,6 @@ pub enum CoefficientCombineRule {
Max,
}

impl Default for CoefficientCombineRule {
fn default() -> Self {
CoefficientCombineRule::Average
}
}

impl CoefficientCombineRule {
pub(crate) fn combine(coeff1: Real, coeff2: Real, rule_value1: u8, rule_value2: u8) -> Real {
let effective_rule = rule_value1.max(rule_value2);
Expand Down
Loading

0 comments on commit da92e5c

Please sign in to comment.