From bc29eddb0e918377c54ced716627cdfd2185bc3b Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Sat, 25 Jan 2025 16:51:12 -0600 Subject: [PATCH] lints --- src/app.rs | 66 ++++++++++++----------- src/body.rs | 1 - src/debug_render.rs | 3 +- src/mesh.rs | 15 ++---- src/prefab.rs | 102 ++++++++++++++++------------------- src/xpbd/builder.rs | 3 +- src/xpbd/constraint/impl_.rs | 4 +- src/xpbd/mod.rs | 35 ++++++------ src/xpbd/set.rs | 4 +- 9 files changed, 106 insertions(+), 127 deletions(-) diff --git a/src/app.rs b/src/app.rs index b47f31e7b..0f823e7fb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -22,7 +22,7 @@ use nalgebra::Vector3; use rapier3d::prelude::*; use crate::body::{self, Body}; -use crate::debug_render::{DebugRenderPipelineResource, RapierDebugRenderPlugin}; +use crate::debug_render::DebugRenderPipelineResource; use crate::either::Either; use crate::mesh::Mesh; use crate::physics::PhysicsState; @@ -93,7 +93,7 @@ impl State { pub fn setup_bodies(&self) -> &[(String, BevyEntity)] { match self { - | Self::Setup { bodies, .. } => &bodies, + | Self::Setup { bodies, .. } => bodies, | _ => unreachable!(), } } @@ -134,7 +134,10 @@ impl State { pub fn setup_done(self, ctx: &mut Ctx) -> Self { match self { - | Self::Setup { debug_render, bodies, freq, .. } => { + | Self::Setup { debug_render, + bodies, + freq, + .. } => { for (_, id) in bodies.iter() { ctx.commands.entity(*id).insert(body::building::Commit); } @@ -170,41 +173,41 @@ impl SetupView { | SetupView::Spawn(a) => a.render(ui, ctx), | SetupView::Init => { ui.vertical(|ui| { - ui.label("Entities"); - let bodies = ctx.state.setup_bodies(); - let mut selected: Option = None; - ComboBox::from_id_salt("choose_entity").show_ui(ui, |ui| { - bodies.iter().for_each(|(name, ent)| { + ui.label("Entities"); + let bodies = ctx.state.setup_bodies(); + let mut selected: Option = None; + ComboBox::from_id_salt("choose_entity").show_ui(ui, |ui| { + bodies.iter().for_each(|(name, ent)| { ui.selectable_value(&mut selected, Some(*ent), name); }); - }); + }); - if let Some(ent) = selected { - ctx.state.setup_nav(SetupView::Transform { ent, - scale_uniform: true }); - } + if let Some(ent) = selected { + ctx.state.setup_nav(SetupView::Transform { ent, + scale_uniform: true }); + } - if button!(ui, "+ Spawn", heading).clicked() { - ctx.state.setup_nav(SetupView::Spawn(Default::default())); - } + if button!(ui, "+ Spawn", heading).clicked() { + ctx.state.setup_nav(SetupView::Spawn(Default::default())); + } - ui.separator(); - ui.horizontal(|ui| { - ui.label("Physics Step Frequency (hz)"); - ui.add(DragValue::new(ctx.state.setup_freq())); - }); + ui.separator(); + ui.horizontal(|ui| { + ui.label("Physics Step Frequency (hz)"); + ui.add(DragValue::new(ctx.state.setup_freq())); + }); - ui.horizontal(|ui| { - ui.checkbox(&mut ctx.state.setup_debug_render(), "Debug Render"); - }); + ui.horizontal(|ui| { + ui.checkbox(ctx.state.setup_debug_render(), "Debug Render"); + }); - ui.separator(); + ui.separator(); - if button!(ui, "Done", heading).clicked() { - *ctx.state = core::mem::take(ctx.state.deref_mut()).setup_done(ctx); - } + if button!(ui, "Done", heading).clicked() { + *ctx.state = core::mem::take(ctx.state.deref_mut()).setup_done(ctx); + } }); }, | SetupView::Error(err) => { @@ -561,10 +564,9 @@ pub fn render(mut ctx: Ctx, mut egui: Query<&mut EguiContext>) { button!(ui, "Load File", heading).clicked(); if button!(ui, "+ New", heading).clicked() { - *ctx.state = State::Setup { - freq: 60.0, - debug_render: false, - bodies: Default::default(), + *ctx.state = State::Setup { freq: 60.0, + debug_render: false, + bodies: Default::default(), view: SetupView::Init }; } }); diff --git a/src/body.rs b/src/body.rs index 042ac355c..6efbf9e80 100644 --- a/src/body.rs +++ b/src/body.rs @@ -129,7 +129,6 @@ pub mod building { pub mod physics { use bevy::prelude as bevy; - use nalgebra::Vector3; use rapier3d::prelude as rapier; use crate::mesh::TriMesh; diff --git a/src/debug_render.rs b/src/debug_render.rs index 705d5a687..0aaaf8377 100644 --- a/src/debug_render.rs +++ b/src/debug_render.rs @@ -4,8 +4,7 @@ use bevy::color::Color; use bevy::prelude::{Gizmos, Query, ResMut, Resource, Transform}; use nalgebra::{SimdValue, Vector3}; use rapier3d::math::Point; -use rapier3d::prelude::{Aabb, - DebugRenderBackend, +use rapier3d::prelude::{DebugRenderBackend, DebugRenderMode, DebugRenderObject, DebugRenderPipeline, diff --git a/src/mesh.rs b/src/mesh.rs index 871793104..e797f82f8 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -1,6 +1,5 @@ use fixed::types::{I24F8, I32F32}; use nalgebra::{Scale3, UnitQuaternion, Vector3}; -use parry3d::query::sat::cuboid_segment_find_local_separating_edge_twoway; use rapier3d::prelude::*; use rustc_hash::{FxHashMap, FxHashSet}; use serde::{Deserialize, Serialize}; @@ -413,13 +412,13 @@ impl Bones { .filter_map(|(ix_, (_, bh, bt, _, _))| { if ix_ == ix { None - } else if !ahl.contains(&ix_) && ah.relative_eq(&bh, 1e-2, f32::EPSILON) { + } else if !ahl.contains(&ix_) && ah.relative_eq(bh, 1e-2, f32::EPSILON) { Some((Link::HH, ix_)) - } else if !atl.contains(&ix_) && at.relative_eq(&bh, 1e-2, f32::EPSILON) { + } else if !atl.contains(&ix_) && at.relative_eq(bh, 1e-2, f32::EPSILON) { Some((Link::TH, ix_)) - } else if !ahl.contains(&ix_) && ah.relative_eq(&bt, 1e-2, f32::EPSILON) { + } else if !ahl.contains(&ix_) && ah.relative_eq(bt, 1e-2, f32::EPSILON) { Some((Link::HT, ix_)) - } else if !atl.contains(&ix_) && at.relative_eq(&bt, 1e-2, f32::EPSILON) { + } else if !atl.contains(&ix_) && at.relative_eq(bt, 1e-2, f32::EPSILON) { Some((Link::TT, ix_)) } else { None @@ -430,11 +429,7 @@ impl Bones { #[allow(clippy::type_complexity)] fn build_graph(ix: usize, - bones: &mut [(&str, - Vector3, - Vector3, - Vec, - Vec)]) { + bones: &mut [(&str, Vector3, Vector3, Vec, Vec)]) { for (link, other) in new_links(ix, bones) { match link { | Link::HT => { diff --git a/src/prefab.rs b/src/prefab.rs index 49b98f710..7b1a3e8ed 100644 --- a/src/prefab.rs +++ b/src/prefab.rs @@ -1,8 +1,7 @@ -use std::collections::VecDeque; use std::sync::LazyLock; -use ::bevy::prelude::{Cuboid, Meshable}; -use ::bevy::render::mesh::{Indices, MeshVertexAttribute, VertexAttributeValues}; +use ::bevy::prelude::Meshable; +use ::bevy::render::mesh::{Indices, VertexAttributeValues}; use bevy::prelude as bevy; use itertools::Itertools; use nalgebra::{vector, Point, Vector3}; @@ -149,64 +148,57 @@ impl Prefab { let tri = self.trimesh(); let msh = Mesh::from_trimesh(&tri.vertices, &tri.faces, Some(0.01)); let mut bones = FxHashMap::default(); - let center = BoneVertex { - x: 0.0, - y: 0.0, - z: 0.0, - }; + let center = BoneVertex { x: 0.0, + y: 0.0, + z: 0.0 }; - let bone_points = vec![ - vector![0.4, 0.4, 0.4], - vector![0.4, 0.4, -0.4], - vector![-0.4, 0.4, 0.4], - vector![-0.4, 0.4, -0.4], - vector![0.4, -0.4, 0.4], - vector![0.4, -0.4, -0.4], - vector![-0.4, -0.4, 0.4], - vector![-0.4, -0.4, -0.4], - ]; + let bone_points = [vector![0.4, 0.4, 0.4], + vector![0.4, 0.4, -0.4], + vector![-0.4, 0.4, 0.4], + vector![-0.4, 0.4, -0.4], + vector![0.4, -0.4, 0.4], + vector![0.4, -0.4, -0.4], + vector![-0.4, -0.4, 0.4], + vector![-0.4, -0.4, -0.4]]; bone_points.iter().enumerate().for_each(|(ix, a)| { - bones.insert( - format!("diag_{}", ix), - Bone { - head: BoneVertex { - x: a.x, - y: a.y, - z: a.z, - }, - tail: center, - }, - ); - }); + bones.insert(format!("diag_{}", ix), + Bone { head: BoneVertex { x: a.x, + y: a.y, + z: a.z }, + tail: center }); + }); - bone_points.iter().copied().enumerate().flat_map(|(ax, a)| bone_points.iter().copied().enumerate().map(move |(bx, b)| (a, ax, b, bx))).for_each(|(a, ax, b, bx)| { - if ax == bx || dbg!((a - b).magnitude()) > 0.8 {return} + bone_points.iter() + .copied() + .enumerate() + .flat_map(|(ax, a)| { + bone_points.iter() + .copied() + .enumerate() + .map(move |(bx, b)| (a, ax, b, bx)) + }) + .for_each(|(a, ax, b, bx)| { + if ax == bx || dbg!((a - b).magnitude()) > 0.8 { + return; + } - let (ax, a, bx, b) = { - if ax < bx { - (ax, a, bx, b) - } else { - (bx, b, ax, a) - } - }; + let (ax, a, bx, b) = { + if ax < bx { + (ax, a, bx, b) + } else { + (bx, b, ax, a) + } + }; - bones.insert( - format!("edge_{}_{}", ax, bx), - Bone { - head: BoneVertex { - x: a.x, - y: a.y, - z: a.z, - }, - tail: BoneVertex { - x: b.x, - y: b.y, - z: b.z, - }, - }, - ); - }); + bones.insert(format!("edge_{}_{}", ax, bx), + Bone { head: BoneVertex { x: a.x, + y: a.y, + z: a.z }, + tail: BoneVertex { x: b.x, + y: b.y, + z: b.z } }); + }); (msh, Bones::new(bones)) }, diff --git a/src/xpbd/builder.rs b/src/xpbd/builder.rs index ce1eba689..d86456b0f 100644 --- a/src/xpbd/builder.rs +++ b/src/xpbd/builder.rs @@ -19,7 +19,6 @@ use rustc_hash::{FxHashMap, FxHashSet}; use super::constraint::{graph, Constraint, Stiffness}; use super::{constraint, step, Body, Handle, Set}; -use crate::either::Either; use crate::mesh::{Mesh, TriMesh}; use crate::xpbd::step::Step; @@ -85,7 +84,7 @@ impl Inserted { linear_damping, &mut extra_dst); - me.faces = faces.into_iter() + me.faces = faces.iter() .map(|a| { a.map(|x| { let v = vertices[x as usize].map(I32F32::from_num); diff --git a/src/xpbd/constraint/impl_.rs b/src/xpbd/constraint/impl_.rs index 3cf996e13..da786aa38 100644 --- a/src/xpbd/constraint/impl_.rs +++ b/src/xpbd/constraint/impl_.rs @@ -177,9 +177,7 @@ pub mod contact { vec![] } - fn init(&mut self, _: &rustc_hash::FxHashMap) { - () - } + fn init(&mut self, _: &rustc_hash::FxHashMap) {} } } diff --git a/src/xpbd/mod.rs b/src/xpbd/mod.rs index 0958fb97b..1b330292b 100644 --- a/src/xpbd/mod.rs +++ b/src/xpbd/mod.rs @@ -1,14 +1,10 @@ use core::f32; use core::fmt::Debug; -use std::collections::BTreeMap; pub use builder::Builder; use constraint::Constraint; pub use handle::Handle; -use nalgebra::Vector3; use rapier3d::parry::bounding_volume::Aabb; -use rapier3d::parry::partitioning::Qbvh; -use rapier3d::parry::query::details::RayCompositeShapeToiAndNormalBestFirstVisitor; use rapier3d::prelude::{RigidBodyHandle, *}; use rustc_hash::FxHashSet; pub use set::Set; @@ -46,7 +42,6 @@ impl Body { } step.predict_next(); - } /// Apply simulation results to rapier environment @@ -110,7 +105,7 @@ impl Body { ix_of_other: usize, other: &parry3d::shape::TriMesh) { if !other.aabb(&Isometry::identity()).intersects(&self.aabb()) { - return + return; } let points = self.step @@ -146,20 +141,20 @@ impl Body { pub fn update_contacts(&mut self, bodies: &[Self]) { // self.constraints - // .iter_mut() - // .filter_map(|c| match c { - // | constraint::impl_::Constraint::Contact(c) => Some(c), - // | _ => None, - // }) - // .for_each(|contact| { - // let face = bodies[contact.other].trimesh[contact.face]; - // let [a, b, c] = face.map(|x| Point::from(bodies[contact.other].step.bodies[x].next.p)); - // let tri = parry3d::shape::Triangle::new(a, b, c); - // let proj = - // tri.project_local_point(&Point::from(self.step.bodies[contact.idx].next.p), false); - // contact.normal = tri.normal().unwrap(); - // contact.contact_point = proj.point.coords; - // }); + // .iter_mut() + // .filter_map(|c| match c { + // | constraint::impl_::Constraint::Contact(c) => Some(c), + // | _ => None, + // }) + // .for_each(|contact| { + // let face = bodies[contact.other].trimesh[contact.face]; + // let [a, b, c] = face.map(|x| Point::from(bodies[contact.other].step.bodies[x].next.p)); + // let tri = parry3d::shape::Triangle::new(a, b, c); + // let proj = + // tri.project_local_point(&Point::from(self.step.bodies[contact.idx].next.p), false); + // contact.normal = tri.normal().unwrap(); + // contact.contact_point = proj.point.coords; + // }); } pub fn aabb(&self) -> Aabb { diff --git a/src/xpbd/set.rs b/src/xpbd/set.rs index 9a731000b..d8c2668e2 100644 --- a/src/xpbd/set.rs +++ b/src/xpbd/set.rs @@ -59,7 +59,7 @@ impl Set { /// Do a single simulation step pub fn step(&self, bodies: &mut RigidBodySet) { let mut bs = self.bodies.lock().unwrap(); - if bs.len() == 0 { + if bs.is_empty() { return; } @@ -115,7 +115,7 @@ impl Set { for (ax, ab) in bsa.iter_mut().enumerate() { // update contact constraints with update face // positions - ab.update_contacts(&bsb); + ab.update_contacts(bsb); if n == 0 || n % substep_interval[ax] == 0 { ab.substep();