Fix clippy and enable clippy on CI

This commit is contained in:
Sébastien Crozet
2024-01-27 16:49:53 +01:00
committed by Sébastien Crozet
parent aef873f20e
commit da92e5c283
81 changed files with 420 additions and 468 deletions

View File

@@ -445,9 +445,8 @@ impl BroadPhase {
);
}
let need_region_propagation = !layer.created_regions.is_empty();
need_region_propagation
// Returns true if propagation is needed.
!layer.created_regions.is_empty()
}
/// Updates the broad-phase, taking into account the new collider positions.

View File

@@ -2,12 +2,12 @@ pub use self::broad_phase::BroadPhase;
pub use self::broad_phase_pair_event::{BroadPhasePairEvent, ColliderPair};
pub use self::sap_proxy::SAPProxyIndex;
pub(self) use self::sap_axis::*;
pub(self) use self::sap_endpoint::*;
pub(self) use self::sap_layer::*;
pub(self) use self::sap_proxy::*;
pub(self) use self::sap_region::*;
pub(self) use self::sap_utils::*;
use self::sap_axis::*;
use self::sap_endpoint::*;
use self::sap_layer::*;
use self::sap_proxy::*;
use self::sap_region::*;
use self::sap_utils::*;
mod broad_phase;
mod broad_phase_pair_event;

View File

@@ -65,9 +65,8 @@ impl SAPAxis {
proxy.aabb,
self.min_bound
);
let start_endpoint =
SAPEndpoint::start_endpoint(proxy.aabb.mins[dim], *proxy_id as u32);
let end_endpoint = SAPEndpoint::end_endpoint(proxy.aabb.maxs[dim], *proxy_id as u32);
let start_endpoint = SAPEndpoint::start_endpoint(proxy.aabb.mins[dim], *proxy_id);
let end_endpoint = SAPEndpoint::end_endpoint(proxy.aabb.maxs[dim], *proxy_id);
self.new_endpoints.push((start_endpoint, 0));
self.new_endpoints.push((end_endpoint, 0));

View File

@@ -15,10 +15,7 @@ pub enum SAPProxyData {
impl SAPProxyData {
pub fn is_region(&self) -> bool {
match self {
SAPProxyData::Region(_) => true,
_ => false,
}
matches!(self, SAPProxyData::Region(_))
}
pub fn as_region(&self) -> &SAPRegion {
@@ -102,7 +99,7 @@ impl SAPProxies {
}
pub fn insert(&mut self, proxy: SAPProxy) -> SAPProxyIndex {
let result = if self.first_free != NEXT_FREE_SENTINEL {
if self.first_free != NEXT_FREE_SENTINEL {
let proxy_id = self.first_free;
self.first_free = self.elements[proxy_id as usize].next_free;
self.elements[proxy_id as usize] = proxy;
@@ -110,15 +107,13 @@ impl SAPProxies {
} else {
self.elements.push(proxy);
self.elements.len() as u32 - 1
};
result
}
}
pub fn remove(&mut self, proxy_id: SAPProxyIndex) {
let proxy = &mut self.elements[proxy_id as usize];
proxy.next_free = self.first_free;
self.first_free = proxy_id as u32;
self.first_free = proxy_id;
}
// NOTE: this must not take holes into account.

View File

@@ -73,6 +73,7 @@ impl SAPRegion {
old
}
#[allow(clippy::vec_box)] // PERF: see if Box actually makes it faster (due to less copying).
pub fn recycle_or_new(bounds: Aabb, pool: &mut Vec<Box<Self>>) -> Box<Self> {
if let Some(old) = pool.pop() {
Self::recycle(bounds, old)

View File

@@ -157,10 +157,7 @@ impl Collider {
/// Is this collider enabled?
pub fn is_enabled(&self) -> bool {
match self.flags.enabled {
ColliderEnabled::Enabled => true,
_ => false,
}
matches!(self.flags.enabled, ColliderEnabled::Enabled)
}
/// Sets whether or not this collider is enabled.
@@ -916,8 +913,8 @@ impl ColliderBuilder {
}
}
impl Into<Collider> for ColliderBuilder {
fn into(self) -> Collider {
self.build()
impl From<ColliderBuilder> for Collider {
fn from(val: ColliderBuilder) -> Collider {
val.build()
}
}

View File

@@ -24,11 +24,11 @@ impl ColliderSet {
}
pub(crate) fn take_modified(&mut self) -> Vec<ColliderHandle> {
std::mem::replace(&mut self.modified_colliders, vec![])
std::mem::take(&mut self.modified_colliders)
}
pub(crate) fn take_removed(&mut self) -> Vec<ColliderHandle> {
std::mem::replace(&mut self.removed_colliders, vec![])
std::mem::take(&mut self.removed_colliders)
}
/// An always-invalid collider handle.

View File

@@ -1,3 +1,5 @@
#![allow(clippy::bad_bit_mask)] // Clippy will complain about the bitmasks due to Group::NONE being 0.
/// Pairwise filtering using bit masks.
///
/// This filtering method is based on two 32-bit values:

View File

@@ -126,7 +126,7 @@ impl NarrowPhase {
/// The returned contact pairs identify pairs of colliders with intersecting bounding-volumes.
/// To check if any geometric contact happened between the collider shapes, check
/// [`ContactPair::has_any_active_contact`].
pub fn contact_pairs_with<'a>(
pub fn contact_pairs_with(
&self,
collider: ColliderHandle,
) -> impl Iterator<Item = &ContactPair> {
@@ -324,7 +324,7 @@ impl NarrowPhase {
&mut self,
intersection_graph_id: ColliderGraphIndex,
contact_graph_id: ColliderGraphIndex,
mut islands: Option<&mut IslandManager>,
islands: Option<&mut IslandManager>,
colliders: &mut ColliderSet,
bodies: &mut RigidBodySet,
prox_id_remap: &mut HashMap<ColliderHandle, ColliderGraphIndex>,
@@ -332,7 +332,7 @@ impl NarrowPhase {
events: &dyn EventHandler,
) {
// Wake up every body in contact with the deleted collider and generate Stopped collision events.
if let Some(islands) = islands.as_deref_mut() {
if let Some(islands) = islands {
for (a, b, pair) in self.contact_graph.interactions_with(contact_graph_id) {
if let Some(parent) = colliders.get(a).and_then(|c| c.parent.as_ref()) {
islands.wake_up(bodies, parent.handle, true)
@@ -539,18 +539,17 @@ impl NarrowPhase {
// Emit an intersection lost event if we had an intersection before removing the edge.
if let Some(mut intersection) = intersection {
if intersection.intersecting {
if (co1.flags.active_events | co2.flags.active_events)
if intersection.intersecting
&& (co1.flags.active_events | co2.flags.active_events)
.contains(ActiveEvents::COLLISION_EVENTS)
{
intersection.emit_stop_event(
bodies,
colliders,
pair.collider1,
pair.collider2,
events,
)
}
{
intersection.emit_stop_event(
bodies,
colliders,
pair.collider1,
pair.collider2,
events,
)
}
}
} else {
@@ -588,15 +587,14 @@ impl NarrowPhase {
if let (Some(co1), Some(co2)) =
(colliders.get(pair.collider1), colliders.get(pair.collider2))
{
if co1.parent.map(|p| p.handle) == co2.parent.map(|p| p.handle) {
if co1.parent.is_some() {
// Same parents. Ignore collisions.
return;
}
// These colliders have no parents - continue.
if co1.parent.map(|p| p.handle) == co2.parent.map(|p| p.handle) && co1.parent.is_some()
{
// Same parents. Ignore collisions.
return;
}
// These colliders have no parents - continue.
let (gid1, gid2) = self.graph_indices.ensure_pair_exists(
pair.collider1.0,
pair.collider2.0,
@@ -712,7 +710,7 @@ impl NarrowPhase {
let co2 = &colliders[handle2];
// TODO: remove the `loop` once labels on blocks is stabilized.
'emit_events: loop {
'emit_events: {
if !co1.changes.needs_narrow_phase_update()
&& !co2.changes.needs_narrow_phase_update()
{
@@ -813,7 +811,7 @@ impl NarrowPhase {
let co2 = &colliders[pair.collider2];
// TODO: remove the `loop` once labels on blocks are supported.
'emit_events: loop {
'emit_events: {
if !co1.changes.needs_narrow_phase_update()
&& !co2.changes.needs_narrow_phase_update()
{
@@ -979,7 +977,7 @@ impl NarrowPhase {
// Apply the user-defined contact modification.
if active_hooks.contains(ActiveHooks::MODIFY_SOLVER_CONTACTS) {
let mut modifiable_solver_contacts =
std::mem::replace(&mut manifold.data.solver_contacts, Vec::new());
std::mem::take(&mut manifold.data.solver_contacts);
let mut modifiable_user_data = manifold.data.user_data;
let mut modifiable_normal = manifold.data.normal;
@@ -1009,13 +1007,13 @@ impl NarrowPhase {
let active_events = co1.flags.active_events | co2.flags.active_events;
if pair.has_any_active_contact != had_any_active_contact {
if active_events.contains(ActiveEvents::COLLISION_EVENTS) {
if pair.has_any_active_contact {
pair.emit_start_event(bodies, colliders, events);
} else {
pair.emit_stop_event(bodies, colliders, events);
}
if pair.has_any_active_contact != had_any_active_contact
&& active_events.contains(ActiveEvents::COLLISION_EVENTS)
{
if pair.has_any_active_contact {
pair.emit_start_event(bodies, colliders, events);
} else {
pair.emit_stop_event(bodies, colliders, events);
}
}
});
@@ -1029,7 +1027,7 @@ impl NarrowPhase {
bodies: &RigidBodySet,
out_contact_pairs: &mut Vec<TemporaryInteractionIndex>,
out_manifolds: &mut Vec<&'a mut ContactManifold>,
out: &mut Vec<Vec<ContactManifoldIndex>>,
out: &mut [Vec<ContactManifoldIndex>],
) {
for out_island in &mut out[..islands.num_islands()] {
out_island.clear();