Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #186

Merged
merged 3 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions .github/workflows/parry-ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@ jobs:
check-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check formatting
run: cargo fmt -- --check
- uses: actions/checkout@v3
- name: Check formatting
run: cargo fmt -- --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Clippy
run: cargo clippy
build-native:
runs-on: ubuntu-latest
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v3
- run: sudo apt-get install -y cmake libxcb-composite0-dev
- name: Build parry2d
run: cargo build --verbose -p parry2d;
- name: Build parry3d
run: cargo build --verbose -p parry3d;
- name: Build parry2d SIMD
run: cd crates/parry2d; cargo build --verbose --features simd-stable;
- name: Build parry3d SIMD
run: cd crates/parry3d; cargo build --verbose --features simd-stable;
- name: Check serialization
run: cargo check --features bytemuck-serialize,serde-serialize,rkyv-serialize;
- name: Run tests
run: cargo test
- uses: actions/checkout@v3
- run: sudo apt-get install -y cmake libxcb-composite0-dev
- name: Build parry2d
run: cargo build --verbose -p parry2d;
- name: Build parry3d
run: cargo build --verbose -p parry3d;
- name: Build parry2d SIMD
run: cd crates/parry2d; cargo build --verbose --features simd-stable;
- name: Build parry3d SIMD
run: cd crates/parry3d; cargo build --verbose --features simd-stable;
- name: Check serialization
run: cargo check --features bytemuck-serialize,serde-serialize,rkyv-serialize;
- name: Run tests
run: cargo test
build-wasm:
runs-on: ubuntu-latest
env:
Expand All @@ -61,19 +67,3 @@ jobs:
run: xargo build --verbose --no-default-features --features required-features --target=x86_64-unknown-linux-gnu;
- name: build thumbv7em-none-eabihf
run: xargo build --verbose --no-default-features --features required-features --target=thumbv7em-none-eabihf;
build-cuda:
runs-on: ubuntu-latest
steps:
- uses: Jimver/[email protected]
with:
cuda: '11.5.0'
- name: Install nightly-2021-12-04
uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2021-12-04
- uses: actions/checkout@v3
- run: rustup target add nvptx64-nvidia-cuda
- run: cargo build --no-default-features --features required-features,cuda
- run: cargo build --no-default-features --features required-features,cuda --target=nvptx64-nvidia-cuda
env:
CUDA_ARCH: "350"
8 changes: 4 additions & 4 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ impl BoundingVolume for Aabb {
#[inline]
fn loosen(&mut self, amount: Real) {
assert!(amount >= 0.0, "The loosening margin must be positive.");
self.mins = self.mins + Vector::repeat(-amount);
self.maxs = self.maxs + Vector::repeat(amount);
self.mins += Vector::repeat(-amount);
self.maxs += Vector::repeat(amount);
}

#[inline]
Expand All @@ -559,8 +559,8 @@ impl BoundingVolume for Aabb {
#[inline]
fn tighten(&mut self, amount: Real) {
assert!(amount >= 0.0, "The tightening margin must be positive.");
self.mins = self.mins + Vector::repeat(amount);
self.maxs = self.maxs + Vector::repeat(-amount);
self.mins += Vector::repeat(amount);
self.maxs += Vector::repeat(-amount);
assert!(
na::partial_le(&self.mins, &self.maxs),
"The tightening margin is to large."
Expand Down
2 changes: 1 addition & 1 deletion src/bounding_volume/aabb_heightfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ impl<Storage: HeightFieldStorage> GenericHeightField<Storage> {
/// Computes the local-space [`Aabb`] of this heightfield.
#[inline]
pub fn local_aabb(&self) -> Aabb {
self.root_aabb().clone()
*self.root_aabb()
}
}
25 changes: 11 additions & 14 deletions src/bounding_volume/bounding_sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,17 @@ impl BoundingVolume for BoundingSphere {
let s_center_dir = self.center.coords.dot(&dir);
let o_center_dir = other.center.coords.dot(&dir);

let right;
let left;

if s_center_dir + self.radius > o_center_dir + other.radius {
right = self.center + dir * self.radius;
let right = if s_center_dir + self.radius > o_center_dir + other.radius {
self.center + dir * self.radius
} else {
right = other.center + dir * other.radius;
}
other.center + dir * other.radius
};

if -s_center_dir + self.radius > -o_center_dir + other.radius {
left = self.center - dir * self.radius;
let left = if -s_center_dir + self.radius > -o_center_dir + other.radius {
self.center - dir * self.radius
} else {
left = other.center - dir * other.radius;
}
other.center - dir * other.radius
};

self.center = na::center(&left, &right);
self.radius = na::distance(&right, &self.center);
Expand All @@ -107,7 +104,7 @@ impl BoundingVolume for BoundingSphere {

#[inline]
fn merged(&self, other: &BoundingSphere) -> BoundingSphere {
let mut res = self.clone();
let mut res = *self;

res.merge(other);

Expand All @@ -117,7 +114,7 @@ impl BoundingVolume for BoundingSphere {
#[inline]
fn loosen(&mut self, amount: Real) {
assert!(amount >= 0.0, "The loosening margin must be positive.");
self.radius = self.radius + amount
self.radius += amount
}

#[inline]
Expand All @@ -130,7 +127,7 @@ impl BoundingVolume for BoundingSphere {
fn tighten(&mut self, amount: Real) {
assert!(amount >= 0.0, "The tightening margin must be positive.");
assert!(amount <= self.radius, "The tightening margin is to large.");
self.radius = self.radius - amount
self.radius -= amount
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/bounding_volume/simd_aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ impl SimdAabb {
/// result between `self.extract(i)` and `other.extract(j)`.
pub fn intersects_permutations(&self, other: &SimdAabb) -> [SimdBool; SIMD_WIDTH] {
let mut result = [SimdBool::splat(false); SIMD_WIDTH];
for ii in 0..SIMD_WIDTH {
for (ii, result) in result.iter_mut().enumerate() {
// TODO: use SIMD-accelerated shuffling?
let extracted = SimdAabb::splat(self.extract(ii));
result[ii] = extracted.intersects(other);
*result = extracted.intersects(other);
}

result
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ the rust programming language.
#![warn(missing_docs)] // TODO: deny this
#![warn(unused_imports)]
#![allow(missing_copy_implementations)]
#![allow(clippy::too_many_arguments)] // Maybe revisit this one later.
#![allow(clippy::module_inception)]
#![allow(clippy::manual_range_contains)] // This usually makes it way more verbose that it could be.
#![allow(clippy::type_complexity)] // Complains about closures that are fairly simple.
#![doc(html_root_url = "http://docs.rs/parry/0.1.1")]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "rkyv"), deny(unused_qualifications))] // TODO: deny that everytime
Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/qbvh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use self::storage::QbvhStorage;

mod qbvh;
mod storage;
pub(self) mod utils;
mod utils;

#[cfg(feature = "std")]
mod build;
Expand Down
9 changes: 8 additions & 1 deletion src/partitioning/qbvh/qbvh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl IndexedData for u32 {

impl IndexedData for u64 {
fn default() -> Self {
u64::MAX as u64
u64::MAX
}
fn index(&self) -> usize {
*self as usize
Expand Down Expand Up @@ -307,6 +307,13 @@ impl<LeafData: DeviceCopy> CudaQbvh<LeafData> {
}
}

#[cfg(feature = "std")]
impl<LeafData: IndexedData> Default for Qbvh<LeafData> {
fn default() -> Self {
Self::new()
}
}

#[cfg(feature = "std")]
impl<LeafData: IndexedData> Qbvh<LeafData> {
/// Initialize an empty Qbvh.
Expand Down
68 changes: 32 additions & 36 deletions src/partitioning/qbvh/traversal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_range_loop)] // This tends to make the traversal code much more verbose that necessary.

use crate::bounding_volume::{Aabb, SimdAabb};
use crate::math::Real;
use crate::partitioning::visitor::SimdSimultaneousVisitStatus;
Expand Down Expand Up @@ -91,14 +93,12 @@ impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData
let bitmask = mask.bitmask();

for ii in 0..SIMD_WIDTH {
if (bitmask & (1 << ii)) != 0 {
if !node.is_leaf() {
// Internal node, visit the child.
// Un fortunately, we have this check because invalid Aabbs
// return a hit as well.
if node.children[ii] as usize <= self.nodes.len() {
stack.push(node.children[ii]);
}
if (bitmask & (1 << ii)) != 0 && !node.is_leaf() {
// Internal node, visit the child.
// Un fortunately, we have this check because invalid Aabbs
// return a hit as well.
if node.children[ii] as usize <= self.nodes.len() {
stack.push(node.children[ii]);
}
}
}
Expand Down Expand Up @@ -297,21 +297,20 @@ impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData
}

for jj in 0..SIMD_WIDTH {
if (bitmask & (1 << jj)) != 0 {
if node2.children[jj] as usize <= qbvh2.nodes.len() {
stack.push((entry.0, node2.children[jj]));
}
if (bitmask & (1 << jj)) != 0
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((entry.0, node2.children[jj]));
}
}
}
(false, true) => {
for ii in 0..SIMD_WIDTH {
let bitmask = mask[ii].bitmask();

if bitmask != 0 {
if node1.children[ii] as usize <= qbvh1.nodes.len() {
stack.push((node1.children[ii], entry.1));
}
if bitmask != 0 && node1.children[ii] as usize <= qbvh1.nodes.len()
{
stack.push((node1.children[ii], entry.1));
}
}
}
Expand All @@ -320,12 +319,11 @@ impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData
let bitmask = mask[ii].bitmask();

for jj in 0..SIMD_WIDTH {
if (bitmask & (1 << jj)) != 0 {
if node1.children[ii] as usize <= qbvh1.nodes.len()
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((node1.children[ii], node2.children[jj]));
}
if (bitmask & (1 << jj)) != 0
&& node1.children[ii] as usize <= qbvh1.nodes.len()
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((node1.children[ii], node2.children[jj]));
}
}
}
Expand Down Expand Up @@ -397,21 +395,20 @@ impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData
}

for jj in 0..SIMD_WIDTH {
if (bitmask & (1 << jj)) != 0 {
if node2.children[jj] as usize <= qbvh2.nodes.len() {
stack.push((entry.0, node2.children[jj]));
}
if (bitmask & (1 << jj)) != 0
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((entry.0, node2.children[jj]));
}
}
}
(false, true) => {
for ii in 0..SIMD_WIDTH {
let bitmask = mask[ii].bitmask();

if bitmask != 0 {
if node1.children[ii] as usize <= qbvh1.nodes.len() {
stack.push((node1.children[ii], entry.1));
}
if bitmask != 0 && node1.children[ii] as usize <= qbvh1.nodes.len()
{
stack.push((node1.children[ii], entry.1));
}
}
}
Expand All @@ -420,12 +417,11 @@ impl<LeafData: IndexedData, Storage: QbvhStorage<LeafData>> GenericQbvh<LeafData
let bitmask = mask[ii].bitmask();

for jj in 0..SIMD_WIDTH {
if (bitmask & (1 << jj)) != 0 {
if node1.children[ii] as usize <= qbvh1.nodes.len()
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((node1.children[ii], node2.children[jj]));
}
if (bitmask & (1 << jj)) != 0
&& node1.children[ii] as usize <= qbvh1.nodes.len()
&& node2.children[jj] as usize <= qbvh2.nodes.len()
{
stack.push((node1.children[ii], node2.children[jj]));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/partitioning/qbvh/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<LeafData: IndexedData> Qbvh<LeafData> {

// If we reached this point, we didn’t find room for our
// new proxy. Create a new root to make more room.
let mut old_root = self.nodes[0].clone();
let mut old_root = self.nodes[0];
old_root.parent = NodeIndex::new(0, 0);

for child_id in old_root.children {
Expand Down Expand Up @@ -569,7 +569,7 @@ impl<LeafData: IndexedData> Qbvh<LeafData> {

let nid = if let Some(nid) = self.free_list.pop() {
self.nodes[nid as usize] = node;
nid as u32
nid
} else {
let nid = self.nodes.len();
self.nodes.push(node);
Expand Down
2 changes: 1 addition & 1 deletion src/partitioning/qbvh/update/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn test_qbvh_random_operations(
qbvh.check_topology();
} else {
// remove aabb
if added_aabb_indices.len() == 0 {
if added_aabb_indices.is_empty() {
continue;
}
let aabb_index =
Expand Down
Loading
Loading