Skip to content

Commit

Permalink
chore: clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed Mar 24, 2024
1 parent e19f9f0 commit 0af902b
Show file tree
Hide file tree
Showing 90 changed files with 586 additions and 645 deletions.
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
43 changes: 20 additions & 23 deletions src/query/closest_points/closest_points_segment_segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ pub fn closest_points_segment_segment_with_locations_nD<const D: usize>(
let e = d2.norm_squared();
let f = d2.dot(&r);

let _0: Real = 0.0;
let _1: Real = 1.0;

let mut s;
let mut t;

let _eps = crate::math::DEFAULT_EPSILON;
if a <= _eps && e <= _eps {
s = _0;
t = _0;
s = 0.0;
t = 0.0;
} else if a <= _eps {
s = _0;
t = na::clamp(f / e, _0, _1);
s = 0.0;
t = na::clamp(f / e, 0.0, 1.0);
} else {
let c = d1.dot(&r);
if e <= _eps {
t = _0;
s = na::clamp(-c / a, _0, _1);
t = 0.0;
s = na::clamp(-c / a, 0.0, 1.0);
} else {
let b = d1.dot(&d2);
let ae = a * e;
Expand All @@ -77,37 +74,37 @@ pub fn closest_points_segment_segment_with_locations_nD<const D: usize>(

// Use absolute and ulps error to test collinearity.
if denom > _eps && !ulps_eq!(ae, bb) {
s = na::clamp((b * f - c * e) / denom, _0, _1);
s = na::clamp((b * f - c * e) / denom, 0.0, 1.0);
} else {
s = _0;
s = 0.0;
}

t = (b * s + f) / e;

if t < _0 {
t = _0;
s = na::clamp(-c / a, _0, _1);
} else if t > _1 {
t = _1;
s = na::clamp((b - c) / a, _0, _1);
if t < 0.0 {
t = 0.0;
s = na::clamp(-c / a, 0.0, 1.0);
} else if t > 1.0 {
t = 1.0;
s = na::clamp((b - c) / a, 0.0, 1.0);
}
}
}

let loc1 = if s == _0 {
let loc1 = if s == 0.0 {
SegmentPointLocation::OnVertex(0)
} else if s == _1 {
} else if s == 1.0 {
SegmentPointLocation::OnVertex(1)
} else {
SegmentPointLocation::OnEdge([_1 - s, s])
SegmentPointLocation::OnEdge([1.0 - s, s])
};

let loc2 = if t == _0 {
let loc2 = if t == 0.0 {
SegmentPointLocation::OnVertex(0)
} else if t == _1 {
} else if t == 1.0 {
SegmentPointLocation::OnVertex(1)
} else {
SegmentPointLocation::OnEdge([_1 - t, t])
SegmentPointLocation::OnEdge([1.0 - t, t])
};

(loc1, loc2)
Expand Down
2 changes: 1 addition & 1 deletion src/query/contact/contact_ball_convex_polyhedron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn contact_convex_polyhedron_ball(
normal1 = shape1
.feature_normal_at_point(f1, &proj.point)
.or_else(|| Unit::try_new(proj.point.coords, crate::math::DEFAULT_EPSILON))
.unwrap_or_else(|| Vector::y_axis());
.unwrap_or_else(Vector::y_axis);
}

if dist <= prediction {
Expand Down
Loading

0 comments on commit 0af902b

Please sign in to comment.