Skip to content

Commit

Permalink
Add clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Azkellas committed Sep 17, 2024
1 parent 9b72d0a commit 71fb161
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 130 deletions.
94 changes: 27 additions & 67 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,70 +19,30 @@ unexpected_cfgs = "warn"

[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
await_holding_lock = "warn"
char_lit_as_u8 = "warn"
checked_conversions = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_markdown = "warn"
empty_enum = "warn"
enum_glob_use = "warn"
exit = "warn"
expl_impl_clone_on_copy = "warn"
explicit_deref_methods = "warn"
explicit_into_iter_loop = "warn"
fallible_impl_from = "warn"
filter_map_next = "warn"
flat_map_option = "warn"
float_cmp_const = "warn"
fn_params_excessive_bools = "warn"
from_iter_instead_of_collect = "warn"
if_let_mutex = "warn"
implicit_clone = "warn"
imprecise_flops = "warn"
inefficient_to_string = "warn"
invalid_upcast_comparisons = "warn"
large_digit_groups = "warn"
large_stack_arrays = "warn"
large_types_passed_by_value = "warn"
let_unit_value = "warn"
linkedlist = "warn"
lossy_float_literal = "warn"
macro_use_imports = "warn"
manual_ok_or = "warn"
map_err_ignore = "warn"
map_flatten = "warn"
map_unwrap_or = "warn"
match_on_vec_items = "warn"
match_same_arms = "warn"
match_wild_err_arm = "warn"
match_wildcard_for_single_variants = "warn"
mem_forget = "warn"
missing_enforced_import_renames = "warn"
mut_mut = "warn"
mutex_integer = "warn"
needless_borrow = "warn"
needless_continue = "warn"
needless_for_each = "warn"
option_option = "warn"
path_buf_push_overwrite = "warn"
ptr_as_ptr = "warn"
rc_mutex = "warn"
ref_option_ref = "warn"
rest_pat_in_fully_bound_structs = "warn"
same_functions_in_if_condition = "warn"
semicolon_if_nothing_returned = "warn"
single_match_else = "warn"
string_add_assign = "warn"
string_add = "warn"
string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
unimplemented = "warn"
unnested_or_patterns = "warn"
unused_self = "warn"
useless_transmute = "warn"
verbose_file_reads = "warn"
zero_sized_map_values = "warn"
# missing_docs_in_private_items = "warn"
pedantic = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
complexity = {level = "warn", priority = -1 }
style = { level = "warn", priority = -1 }

significant_drop_tightening = "allow"
module_name_repetitions = "allow"
cast_sign_loss = "allow"
cast_precision_loss = "allow"
cast_possible_truncation = "allow"
missing_errors_doc = "allow"
missing_panics_doc = "allow"

# From restriction
same_name_method = "allow" # because of rust embed, see https://github.com/pyrossh/rust-embed/issues/204
std_instead_of_core = "warn"
clone_on_ref_ptr = "warn"
renamed_function_params = "warn"
#unseparated_literal_suffix = "warn"
redundant_type_annotations = "warn"
partial_pub_fields = "warn"
let_underscore_untyped = "warn"
let_underscore_must_use = "warn"
ref_patterns = "warn"
undocumented_unsafe_blocks = "warn"
wildcard_enum_match_arm = "warn"
suboptimal_flops = "allow"
23 changes: 12 additions & 11 deletions mesh_to_sdf/src/bvh_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl AabbExt for Aabb<f32, 3> {
// Invert the signum to get the furthest vertex
.map(|x| -x.signum())
// Make sure we're always on a vertex and not on a face if the point is aligned with the box
.map(|x| if x != 0.0 { x } else { 1.0 });
.map(|x| if x == 0.0 { 1.0 } else { x });

let furthest = center + signum.component_mul(&half_size);
let max_dist = (n_point - furthest).norm();
Expand All @@ -65,7 +65,7 @@ pub trait BvhDistance<V: Point, Shape: Bounded<f32, 3>> {
///
fn nearest_candidates(&self, origin: &V, shapes: &[Shape]) -> Vec<usize>
where
Self: std::marker::Sized;
Self: core::marker::Sized;
}

impl<V: Point, Shape: Bounded<f32, 3>> BvhDistance<V, Shape> for Bvh<f32, 3> {
Expand Down Expand Up @@ -107,13 +107,14 @@ pub trait BvhTraverseDistance<V: Point, Shape: Bounded<f32, 3>> {
best_min_distance: &mut f32,
best_max_distance: &mut f32,
) where
Self: std::marker::Sized;
Self: core::marker::Sized;
}

impl<V: Point, Shape: Bounded<f32, 3>> BvhTraverseDistance<V, Shape> for BvhNode<f32, 3> {
/// Traverses the [`Bvh`] recursively and returns all shapes whose [`Aabb`] countains
/// a candidate shape for being the nearest to the given point.
///
#[expect(clippy::similar_names)]
fn nearest_candidates_recursive(
nodes: &[Self],
node_index: usize,
Expand All @@ -123,11 +124,11 @@ impl<V: Point, Shape: Bounded<f32, 3>> BvhTraverseDistance<V, Shape> for BvhNode
best_min_distance: &mut f32,
best_max_distance: &mut f32,
) {
match nodes[node_index] {
BvhNode::Node {
ref child_l_aabb,
match &nodes[node_index] {
Self::Node {
child_l_aabb,
child_l_index,
ref child_r_aabb,
child_r_aabb,
child_r_index,
..
} => {
Expand All @@ -153,7 +154,7 @@ impl<V: Point, Shape: Bounded<f32, 3>> BvhTraverseDistance<V, Shape> for BvhNode
if dist_min <= *best_max_distance {
Self::nearest_candidates_recursive(
nodes,
index,
*index,
origin,
shapes,
indices,
Expand All @@ -163,8 +164,8 @@ impl<V: Point, Shape: Bounded<f32, 3>> BvhTraverseDistance<V, Shape> for BvhNode
}
}
}
BvhNode::Leaf { shape_index, .. } => {
let aabb = shapes[shape_index].aabb();
Self::Leaf { shape_index, .. } => {
let aabb = shapes[*shape_index].aabb();
let (min_dist, max_dist) = aabb.get_min_max_distances(origin);

if !indices.is_empty() && max_dist < *best_min_distance {
Expand All @@ -177,7 +178,7 @@ impl<V: Point, Shape: Bounded<f32, 3>> BvhTraverseDistance<V, Shape> for BvhNode
*best_max_distance = best_max_distance.min(max_dist);

// we reached a leaf, we add it to the list of indices since it is a potential candidate
indices.push((shape_index, min_dist));
indices.push((*shape_index, min_dist));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions mesh_to_sdf/src/generate/generic/bvh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Module containing the `generate_sdf_bvh` function.
use std::cmp::Ordering;
use core::cmp::Ordering;

use bvh::{bounding_hierarchy::BoundingHierarchy, bvh::Bvh};
use itertools::Itertools;
Expand All @@ -12,7 +12,7 @@ use crate::{bvh_ext::BvhDistance, compare_distances, geo, Point, SignMethod, Top
/// Public in the crate so that the grid generation can use it.
/// `RtreeBvh` uses its own version of this struct to be able to implement the `RTreeObject` trait.
#[derive(Clone)]
pub(crate) struct BvhNode<V: Point> {
pub struct BvhNode<V: Point> {
pub vertex_indices: (usize, usize, usize),
pub node_index: usize,
pub bounding_box: (V, V),
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<V: Point> bvh::bounding_hierarchy::BHShape<f32, 3> for BvhNode<V> {
///
/// Returns a vector of signed distances.
/// Queries outside the mesh will have a positive distance, and queries inside the mesh will have a negative distance.
pub(crate) fn generate_sdf_bvh<V, I>(
pub fn generate_sdf_bvh<V, I>(
vertices: &[V],
indices: Topology<I>,
query_points: &[V],
Expand Down
10 changes: 6 additions & 4 deletions mesh_to_sdf/src/generate/generic/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{compare_distances, geo, Point, SignMethod, Topology};
///
/// Returns a vector of signed distances.
/// Queries outside the mesh will have a positive distance, and queries inside the mesh will have a negative distance.
pub(crate) fn generate_sdf_default<V, I>(
pub fn generate_sdf_default<V, I>(
vertices: &[V],
indices: Topology<I>,
query_points: &[V],
Expand Down Expand Up @@ -47,12 +47,14 @@ where
match sign_method {
SignMethod::Raycast => (
min_distance.min(distance),
intersection_count + ray_intersection as u32,
intersection_count + u32::from(ray_intersection),
),
SignMethod::Normal => (
match compare_distances(distance, min_distance) {
std::cmp::Ordering::Less => distance,
_ => min_distance,
core::cmp::Ordering::Less => distance,
core::cmp::Ordering::Equal | core::cmp::Ordering::Greater => {
min_distance
}
},
intersection_count,
),
Expand Down
8 changes: 4 additions & 4 deletions mesh_to_sdf/src/generate/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Module containing the different `generate_sdf` functions, one for each acceleration structure.
pub(crate) mod bvh;
pub(crate) mod default;
pub(crate) mod rtree;
pub(crate) mod rtree_bvh;
pub mod bvh;
pub mod default;
pub mod rtree;
pub mod rtree_bvh;
4 changes: 2 additions & 2 deletions mesh_to_sdf/src/generate/generic/rtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
let x = generator(0);
let y = generator(1);
let z = generator(2);
PointWrapper(V::new(x, y, z))
Self(V::new(x, y, z))
}

fn nth(&self, index: usize) -> Self::Scalar {
Expand Down Expand Up @@ -84,7 +84,7 @@ impl<V: Point> rstar::PointDistance for RtreeNode<V> {
///
/// This method is only compatible with normal sign method.
/// If you want to use raycasting, use `AccelerationMethod::RtreeBvh` instead.
pub(crate) fn generate_sdf_rtree<V, I>(
pub fn generate_sdf_rtree<V, I>(
vertices: &[V],
indices: Topology<I>,
query_points: &[V],
Expand Down
Loading

0 comments on commit 71fb161

Please sign in to comment.