Skip to content

Commit

Permalink
lints: Remove unnecessary qualifications. (#203)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
waywardmonkeys committed May 28, 2024
1 parent 5f9bfb0 commit 9e723ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 239 deletions.
13 changes: 5 additions & 8 deletions src/partitioning/visitor.rs
Original file line number Diff line number Diff line change
@@ -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<Res> {
Expand Down Expand Up @@ -119,7 +117,7 @@ pub trait SimdSimultaneousVisitor<T1, T2, SimdBV> {
*/

/// 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<LeafData>: Sync {
/// Execute an operation on the content of a node of the spatial partitioning structure.
///
Expand All @@ -133,7 +131,7 @@ pub trait ParallelSimdVisitor<LeafData>: Sync {
) -> SimdVisitStatus;
}

#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "parallel"))]
impl<F, LeafData> ParallelSimdVisitor<LeafData> for F
where
F: Sync + Fn(&QbvhNode, Option<[Option<&LeafData>; SIMD_WIDTH]>) -> SimdVisitStatus,
Expand All @@ -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<LeafData1, LeafData2>: Sync {
/// Visitor state data that will be passed down the recursion.
type Data: Copy + Sync + Default;
Expand Down
4 changes: 2 additions & 2 deletions src/shape/trimesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."))
Expand Down
4 changes: 2 additions & 2 deletions src/transformation/convex_hull3/initial_mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
228 changes: 1 addition & 227 deletions src/utils/wops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -72,36 +69,6 @@ impl WSign<SimdReal> 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.
Expand Down Expand Up @@ -137,118 +104,6 @@ impl<N: SimdRealField + Copy + WSign<N>> WBasis for Vector3<N> {
}
}

pub(crate) trait WVec: Sized {
type Element;

fn horizontal_inf(&self) -> Self::Element;
fn horizontal_sup(&self) -> Self::Element;
}

impl<N: Scalar + Copy + WComponent> WVec for Vector2<N>
where
N::Element: Scalar,
{
type Element = Vector2<N::Element>;

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<N: Scalar + Copy + WComponent> WVec for Point2<N>
where
N::Element: Scalar,
{
type Element = Point2<N::Element>;

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<N: Scalar + Copy + WComponent> WVec for Vector3<N>
where
N::Element: Scalar,
{
type Element = Vector3<N::Element>;

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<N: Scalar + Copy + WComponent> WVec for Point3<N>
where
N::Element: Scalar,
{
type Element = Point3<N::Element>;

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<Real> {
type CrossMat = Matrix3<Real>;

#[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<Real> {
type CrossMat = Vector2<Real>;

#[inline]
fn gcross_matrix(self) -> Self::CrossMat {
Vector2::new(-self.y, self.x)
}
}

pub(crate) trait WCross<Rhs>: Sized {
type Result;
fn gcross(&self, rhs: Rhs) -> Self::Result;
Expand Down Expand Up @@ -278,60 +133,6 @@ impl WCross<Vector2<Real>> for Real {
}
}

pub(crate) trait WDot<Rhs>: Sized {
type Result;
fn gdot(&self, rhs: Rhs) -> Self::Result;
}

impl WDot<Vector3<Real>> for Vector3<Real> {
type Result = Real;

fn gdot(&self, rhs: Vector3<Real>) -> Self::Result {
self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
}
}

impl WDot<Vector2<Real>> for Vector2<Real> {
type Result = Real;

fn gdot(&self, rhs: Vector2<Real>) -> Self::Result {
self.x * rhs.x + self.y * rhs.y
}
}

impl WDot<Real> for Real {
type Result = Real;

fn gdot(&self, rhs: Real) -> Self::Result {
*self * rhs
}
}

#[cfg(feature = "simd-is-enabled")]
impl WCrossMatrix for Vector3<SimdReal> {
type CrossMat = Matrix3<SimdReal>;

#[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<SimdReal> {
type CrossMat = Vector2<SimdReal>;

#[inline]
fn gcross_matrix(self) -> Self::CrossMat {
Vector2::new(-self.y, self.x)
}
}

#[cfg(feature = "simd-is-enabled")]
impl WCross<Vector3<SimdReal>> for Vector3<SimdReal> {
type Result = Vector3<SimdReal>;
Expand Down Expand Up @@ -360,30 +161,3 @@ impl WCross<Vector2<SimdReal>> for Vector2<SimdReal> {
prod.x - prod.y
}
}

#[cfg(feature = "simd-is-enabled")]
impl WDot<Vector3<SimdReal>> for Vector3<SimdReal> {
type Result = SimdReal;

fn gdot(&self, rhs: Vector3<SimdReal>) -> Self::Result {
self.x * rhs.x + self.y * rhs.y + self.z * rhs.z
}
}

#[cfg(feature = "simd-is-enabled")]
impl WDot<Vector2<SimdReal>> for Vector2<SimdReal> {
type Result = SimdReal;

fn gdot(&self, rhs: Vector2<SimdReal>) -> Self::Result {
self.x * rhs.x + self.y * rhs.y
}
}

#[cfg(feature = "simd-is-enabled")]
impl WDot<SimdReal> for SimdReal {
type Result = SimdReal;

fn gdot(&self, rhs: SimdReal) -> Self::Result {
*self * rhs
}
}

0 comments on commit 9e723ee

Please sign in to comment.