diff --git a/src/hgrid.rs b/src/hgrid.rs index bb2a36c..03c2eff 100644 --- a/src/hgrid.rs +++ b/src/hgrid.rs @@ -84,7 +84,7 @@ impl HGrid { /// Inserts the given `element` into the cell containing the given `point`. pub fn insert(&mut self, point: &Point3, element: T) { let key = self.key(point); - self.cells.entry(key).or_insert_with(Vec::new).push(element) + self.cells.entry(key).or_default().push(element); } /// Returns the element attached to the cell containing the given `point`. diff --git a/src/lib.rs b/src/lib.rs index 1b35b63..76e3fb3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,8 @@ Rust implementation of the [Screened poisson reconstruction](https://www.cs.jhu. by Kazhdan and Hoppe. */ +#![warn(clippy::pedantic)] +#![warn(clippy::perf)] #![allow(clippy::type_complexity, clippy::too_many_arguments)] #![warn(missing_docs)] diff --git a/src/marching_cubes.rs b/src/marching_cubes.rs index 686742f..8ae30f3 100644 --- a/src/marching_cubes.rs +++ b/src/marching_cubes.rs @@ -19,16 +19,19 @@ pub struct MeshBuffers { impl MeshBuffers { /// The mesh’s index buffer. + #[must_use] pub fn indices(&self) -> &[u32] { &self.indices } /// The mesh’s vertex buffer. + #[must_use] pub fn vertices(&self) -> &[Point3] { &self.vertices } /// Return the results as a soup of triangle, with duplicated vertices. + #[must_use] pub fn result_as_triangle_soup(&self) -> Vec> { self.indices .iter() @@ -39,6 +42,7 @@ impl MeshBuffers { /// Constructs a `TriMesh` from this buffer. /// /// The result is `None` if the index buffer of `self` is empty. + #[must_use] pub fn result(&self, flags: TriMeshFlags) -> Option { let idx: Vec<_> = self .indices @@ -179,14 +183,14 @@ pub(crate) fn march_cube_idx( let local_corner_1 = INDEX_TO_VERTEX[v1 as usize]; let eid0 = [ - first_corner_cell_key[0] + local_corner_0[0] as i32, - first_corner_cell_key[1] + local_corner_0[1] as i32, - first_corner_cell_key[2] + local_corner_0[2] as i32, + first_corner_cell_key[0] + i32::from(local_corner_0[0]), + first_corner_cell_key[1] + i32::from(local_corner_0[1]), + first_corner_cell_key[2] + i32::from(local_corner_0[2]), ]; let eid1 = [ - first_corner_cell_key[0] + local_corner_1[0] as i32, - first_corner_cell_key[1] + local_corner_1[1] as i32, - first_corner_cell_key[2] + local_corner_1[2] as i32, + first_corner_cell_key[0] + i32::from(local_corner_1[0]), + first_corner_cell_key[1] + i32::from(local_corner_1[1]), + first_corner_cell_key[2] + i32::from(local_corner_1[2]), ]; let edge_key = SortedPair::new(eid0, eid1); @@ -229,9 +233,9 @@ fn lerp_vertices(va: &[u8; 3], vb: &[u8; 3], fa: Real, fb: Real, isoval: Real) - }; Point3::new( - va[0] as Real + (vb[0] as Real - va[0] as Real) * t, - va[1] as Real + (vb[1] as Real - va[1] as Real) * t, - va[2] as Real + (vb[2] as Real - va[2] as Real) * t, + Real::from(va[0]) + (Real::from(vb[0]) - Real::from(va[0])) * t, + Real::from(va[1]) + (Real::from(vb[1]) - Real::from(va[1])) * t, + Real::from(va[2]) + (Real::from(vb[2]) - Real::from(va[2])) * t, ) } diff --git a/src/poisson.rs b/src/poisson.rs index 04092f9..38526d8 100644 --- a/src/poisson.rs +++ b/src/poisson.rs @@ -57,6 +57,7 @@ impl PoissonReconstruction { /// value). Higher values increases computation times. /// - `max_relaxation_iters`: the maximum number of iterations for the internal /// conjugate-gradient solver. Values around `10` should be enough for most cases. + #[must_use] pub fn from_points_and_normals( points: &[Point3], normals: &[Vector3], @@ -125,11 +126,13 @@ impl PoissonReconstruction { } /// The domain where the surface’s implicit function is defined. + #[must_use] pub fn aabb(&self) -> &Aabb { self.layers.last().unwrap().cells_qbvh.root_aabb() } /// Does the given AABB intersect any of the smallest grid cells of the reconstruction? + #[must_use] pub fn leaf_cells_intersect_aabb(&self, aabb: &Aabb) -> bool { let mut intersections = vec![]; self.layers @@ -143,6 +146,7 @@ impl PoissonReconstruction { /// Evaluates the value of the implicit function at the given 3D point. /// /// In order to get a meaningful value, the point must be located inside of [`Self::aabb`]. + #[must_use] pub fn eval(&self, pt: &Point3) -> Real { let mut result = 0.0; @@ -156,6 +160,7 @@ impl PoissonReconstruction { /// Evaluates the value of the implicit function’s gradient at the given 3D point. /// /// In order to get a meaningful value, the point must be located inside of [`Self::aabb`]. + #[must_use] pub fn eval_gradient(&self, pt: &Point3) -> Vector3 { let mut result = Vector3::zeros(); @@ -169,18 +174,21 @@ impl PoissonReconstruction { /// Reconstructs a mesh from this implicit function using a simple marching-cubes, extracting /// the isosurface at 0. #[deprecated = "use `reconstruct_mesh_buffers` or `reconstruct_trimesh` instead"] + #[must_use] pub fn reconstruct_mesh(&self) -> Vec> { self.reconstruct_mesh_buffers().result_as_triangle_soup() } /// Reconstructs a `TriMesh` from this implicit function using a simple marching-cubes, extracting /// the isosurface at 0. + #[must_use] pub fn reconstruct_trimesh(&self, flags: TriMeshFlags) -> Option { self.reconstruct_mesh_buffers().result(flags) } /// Reconstructs a mesh from this implicit function using a simple marching-cubes, extracting /// the isosurface at 0. + #[must_use] pub fn reconstruct_mesh_buffers(&self) -> MeshBuffers { let mut result = MeshBuffers::default(); let mut visited = HashMap::new(); diff --git a/src/poisson_layer.rs b/src/poisson_layer.rs index 863b2f6..911f060 100644 --- a/src/poisson_layer.rs +++ b/src/poisson_layer.rs @@ -147,8 +147,8 @@ impl PoissonLayer { Self { grid, cells_qbvh, - ordered_nodes, grid_node_idx, + ordered_nodes, node_weights, } } diff --git a/src/polynomial.rs b/src/polynomial.rs index bee349c..a7be7ce 100644 --- a/src/polynomial.rs +++ b/src/polynomial.rs @@ -17,7 +17,7 @@ impl TriQuadraticBspline { let mut result = 1.0; for i in 0..3 { - result *= eval_bspline(pt[i], self.center[i], self.width) + result *= eval_bspline(pt[i], self.center[i], self.width); } result