From 9e723ee3f066da9b61eb4023fe393ff4f81125d3 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Tue, 28 May 2024 23:00:26 +0700 Subject: [PATCH] lints: Remove unnecessary qualifications. (#203) * lints: Remove unnecessary qualifications. * Remove unused code in wops.rs This code is now triggering Rust compiler warnings and breaking CI. * partitioning: Mark code as only for parallel + std This code triggers warnings (and errors in CI) because it isn't used when the `parallel` feature isn't enabled, so correctly mark it as needing `all(feature = "parallel", feature = "std")` * Remove unused import of `na::SimdPartialOrd` --- src/partitioning/visitor.rs | 13 +- src/shape/trimesh.rs | 4 +- .../convex_hull3/initial_mesh.rs | 4 +- src/utils/wops.rs | 228 +----------------- 4 files changed, 10 insertions(+), 239 deletions(-) diff --git a/src/partitioning/visitor.rs b/src/partitioning/visitor.rs index dc751c94..dd9f9b27 100644 --- a/src/partitioning/visitor.rs +++ b/src/partitioning/visitor.rs @@ -1,9 +1,7 @@ use crate::math::{Real, SimdBool, SimdReal, SIMD_WIDTH}; -#[cfg(feature = "std")] -use crate::partitioning::qbvh::QbvhNode; -#[cfg(feature = "std")] -use crate::partitioning::SimdNodeIndex; +#[cfg(all(feature = "std", feature = "parallel"))] +use crate::partitioning::{qbvh::QbvhNode, SimdNodeIndex}; /// The next action to be taken by a BVH traversal algorithm after having visited a node with some data. pub enum SimdBestFirstVisitStatus { @@ -119,7 +117,7 @@ pub trait SimdSimultaneousVisitor { */ /// Trait implemented by visitor called during the parallel traversal of a spatial partitioning data structure. -#[cfg(feature = "std")] +#[cfg(all(feature = "std", feature = "parallel"))] pub trait ParallelSimdVisitor: Sync { /// Execute an operation on the content of a node of the spatial partitioning structure. /// @@ -133,7 +131,7 @@ pub trait ParallelSimdVisitor: Sync { ) -> SimdVisitStatus; } -#[cfg(feature = "std")] +#[cfg(all(feature = "std", feature = "parallel"))] impl ParallelSimdVisitor for F where F: Sync + Fn(&QbvhNode, Option<[Option<&LeafData>; SIMD_WIDTH]>) -> SimdVisitStatus, @@ -150,8 +148,7 @@ where /// Trait implemented by visitor called during a parallel simultaneous spatial partitioning /// data structure traversal. -#[cfg(feature = "parallel")] -#[cfg(feature = "std")] +#[cfg(all(feature = "std", feature = "parallel"))] pub trait ParallelSimdSimultaneousVisitor: Sync { /// Visitor state data that will be passed down the recursion. type Data: Copy + Sync + Default; diff --git a/src/shape/trimesh.rs b/src/shape/trimesh.rs index c0d55240..e1237c63 100644 --- a/src/shape/trimesh.rs +++ b/src/shape/trimesh.rs @@ -37,8 +37,8 @@ pub enum TopologyError { }, } -impl std::fmt::Display for TopologyError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for TopologyError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::BadTriangle(fid) => { f.pad(&format!("the triangle {fid} has at least two identical vertices.")) diff --git a/src/transformation/convex_hull3/initial_mesh.rs b/src/transformation/convex_hull3/initial_mesh.rs index 30ba8b47..62f54b6a 100644 --- a/src/transformation/convex_hull3/initial_mesh.rs +++ b/src/transformation/convex_hull3/initial_mesh.rs @@ -46,7 +46,7 @@ pub fn try_get_initial_mesh( #[cfg(not(feature = "improved_fixed_point_support"))] { - let cov_mat = crate::utils::cov(normalized_points); + let cov_mat = utils::cov(normalized_points); let eig = cov_mat.symmetric_eigen(); eigvec = eig.eigenvectors; eigval = eig.eigenvalues; @@ -140,7 +140,7 @@ pub fn try_get_initial_mesh( 3 => { // The hull is a polyhedron. // Find a initial triangle lying on the principal halfspaceā€¦ - let center = crate::utils::center(normalized_points); + let center = utils::center(normalized_points); for point in normalized_points.iter_mut() { *point = Point3::from((*point - center) / eigval.amax()); diff --git a/src/utils/wops.rs b/src/utils/wops.rs index 648ae745..6eac713a 100644 --- a/src/utils/wops.rs +++ b/src/utils/wops.rs @@ -2,12 +2,9 @@ use crate::math::Real; use crate::simd::{SimdBool, SimdReal}; -use na::{Matrix3, Point2, Point3, Scalar, SimdRealField, Vector2, Vector3}; +use na::{Scalar, SimdRealField, Vector2, Vector3}; use simba::simd::SimdValue; -#[cfg(feature = "simd-is-enabled")] -use na::SimdPartialOrd; - /// Conditionally swaps each lanes of `a` with those of `b`. /// /// For each `i in [0..SIMD_WIDTH[`, if `do_swap.extract(i)` is `true` then @@ -72,36 +69,6 @@ impl WSign for SimdReal { } } -pub(crate) trait WComponent: Sized { - type Element; - - fn min_component(self) -> Self::Element; - fn max_component(self) -> Self::Element; -} - -impl WComponent for Real { - type Element = Real; - - fn min_component(self) -> Self::Element { - self - } - fn max_component(self) -> Self::Element { - self - } -} - -#[cfg(feature = "simd-is-enabled")] -impl WComponent for SimdReal { - type Element = Real; - - fn min_component(self) -> Self::Element { - self.simd_horizontal_min() - } - fn max_component(self) -> Self::Element { - self.simd_horizontal_max() - } -} - /// Trait to compute the orthonormal basis of a vector. pub trait WBasis: Sized { /// The type of the array of orthonormal vectors. @@ -137,118 +104,6 @@ impl> WBasis for Vector3 { } } -pub(crate) trait WVec: Sized { - type Element; - - fn horizontal_inf(&self) -> Self::Element; - fn horizontal_sup(&self) -> Self::Element; -} - -impl WVec for Vector2 -where - N::Element: Scalar, -{ - type Element = Vector2; - - fn horizontal_inf(&self) -> Self::Element { - Vector2::new(self.x.min_component(), self.y.min_component()) - } - - fn horizontal_sup(&self) -> Self::Element { - Vector2::new(self.x.max_component(), self.y.max_component()) - } -} - -impl WVec for Point2 -where - N::Element: Scalar, -{ - type Element = Point2; - - fn horizontal_inf(&self) -> Self::Element { - Point2::new(self.x.min_component(), self.y.min_component()) - } - - fn horizontal_sup(&self) -> Self::Element { - Point2::new(self.x.max_component(), self.y.max_component()) - } -} - -impl WVec for Vector3 -where - N::Element: Scalar, -{ - type Element = Vector3; - - fn horizontal_inf(&self) -> Self::Element { - Vector3::new( - self.x.min_component(), - self.y.min_component(), - self.z.min_component(), - ) - } - - fn horizontal_sup(&self) -> Self::Element { - Vector3::new( - self.x.max_component(), - self.y.max_component(), - self.z.max_component(), - ) - } -} - -impl WVec for Point3 -where - N::Element: Scalar, -{ - type Element = Point3; - - fn horizontal_inf(&self) -> Self::Element { - Point3::new( - self.x.min_component(), - self.y.min_component(), - self.z.min_component(), - ) - } - - fn horizontal_sup(&self) -> Self::Element { - Point3::new( - self.x.max_component(), - self.y.max_component(), - self.z.max_component(), - ) - } -} - -pub(crate) trait WCrossMatrix: Sized { - type CrossMat; - - fn gcross_matrix(self) -> Self::CrossMat; -} - -impl WCrossMatrix for Vector3 { - type CrossMat = Matrix3; - - #[inline] - #[rustfmt::skip] - fn gcross_matrix(self) -> Self::CrossMat { - Matrix3::new( - 0.0, -self.z, self.y, - self.z, 0.0, -self.x, - -self.y, self.x, 0.0, - ) - } -} - -impl WCrossMatrix for Vector2 { - type CrossMat = Vector2; - - #[inline] - fn gcross_matrix(self) -> Self::CrossMat { - Vector2::new(-self.y, self.x) - } -} - pub(crate) trait WCross: Sized { type Result; fn gcross(&self, rhs: Rhs) -> Self::Result; @@ -278,60 +133,6 @@ impl WCross> for Real { } } -pub(crate) trait WDot: Sized { - type Result; - fn gdot(&self, rhs: Rhs) -> Self::Result; -} - -impl WDot> for Vector3 { - type Result = Real; - - fn gdot(&self, rhs: Vector3) -> Self::Result { - self.x * rhs.x + self.y * rhs.y + self.z * rhs.z - } -} - -impl WDot> for Vector2 { - type Result = Real; - - fn gdot(&self, rhs: Vector2) -> Self::Result { - self.x * rhs.x + self.y * rhs.y - } -} - -impl WDot for Real { - type Result = Real; - - fn gdot(&self, rhs: Real) -> Self::Result { - *self * rhs - } -} - -#[cfg(feature = "simd-is-enabled")] -impl WCrossMatrix for Vector3 { - type CrossMat = Matrix3; - - #[inline] - #[rustfmt::skip] - fn gcross_matrix(self) -> Self::CrossMat { - Matrix3::new( - num::zero(), -self.z, self.y, - self.z, num::zero(), -self.x, - -self.y, self.x, num::zero(), - ) - } -} - -#[cfg(feature = "simd-is-enabled")] -impl WCrossMatrix for Vector2 { - type CrossMat = Vector2; - - #[inline] - fn gcross_matrix(self) -> Self::CrossMat { - Vector2::new(-self.y, self.x) - } -} - #[cfg(feature = "simd-is-enabled")] impl WCross> for Vector3 { type Result = Vector3; @@ -360,30 +161,3 @@ impl WCross> for Vector2 { prod.x - prod.y } } - -#[cfg(feature = "simd-is-enabled")] -impl WDot> for Vector3 { - type Result = SimdReal; - - fn gdot(&self, rhs: Vector3) -> Self::Result { - self.x * rhs.x + self.y * rhs.y + self.z * rhs.z - } -} - -#[cfg(feature = "simd-is-enabled")] -impl WDot> for Vector2 { - type Result = SimdReal; - - fn gdot(&self, rhs: Vector2) -> Self::Result { - self.x * rhs.x + self.y * rhs.y - } -} - -#[cfg(feature = "simd-is-enabled")] -impl WDot for SimdReal { - type Result = SimdReal; - - fn gdot(&self, rhs: SimdReal) -> Self::Result { - *self * rhs - } -}