Skip to content

Commit 6b711a8

Browse files
committed
Loosen trait bounds on structs and enums
1 parent f7c7004 commit 6b711a8

File tree

7 files changed

+28
-42
lines changed

7 files changed

+28
-42
lines changed

splashsurf_lib/src/aabb.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
//! Axis-aligned bounding boxes
22
3-
use std::fmt;
4-
use std::fmt::Debug;
5-
63
use nalgebra::SVector;
74
use rayon::prelude::*;
85

9-
use crate::{Real, RealConvert, ThreadSafe};
6+
use crate::{Real, RealConvert, Scalar, ThreadSafe};
107

118
/// Type representing an axis aligned bounding box in arbitrary dimensions
12-
#[derive(Clone, Eq, PartialEq)]
13-
pub struct AxisAlignedBoundingBox<R: Real, const D: usize> {
9+
#[derive(Clone, Debug, Eq, PartialEq)]
10+
pub struct AxisAlignedBoundingBox<R: Scalar, const D: usize> {
1411
min: SVector<R, D>,
1512
max: SVector<R, D>,
1613
}
@@ -274,19 +271,6 @@ where
274271
}
275272
}
276273

277-
impl<R, const D: usize> Debug for AxisAlignedBoundingBox<R, D>
278-
where
279-
R: Real,
280-
{
281-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
282-
write!(
283-
f,
284-
"AxisAlignedBoundingBox {{ min: [{:.7}, {:.7}, {:.7}], max: [{:.7}, {:.7}, {:.7}] }}",
285-
self.min[0], self.min[1], self.min[2], self.max[0], self.max[1], self.max[2]
286-
)
287-
}
288-
}
289-
290274
#[test]
291275
fn test_aabb_contains_point() {
292276
use crate::nalgebra::Vector3;

splashsurf_lib/src/density_map.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ use crate::utils::{ChunkSize, ParallelPolicy};
3232
use crate::{HashState, Index, MapType, ParallelMapType, Real, new_map, profile};
3333
use dashmap::ReadOnlyView as ReadDashMap;
3434
use log::{info, trace, warn};
35-
use nalgebra::Vector3;
35+
use nalgebra::{Scalar, Vector3};
3636
use rayon::prelude::*;
3737
use std::borrow::Cow;
3838
use std::cell::RefCell;
39+
use std::hash::Hash;
3940
use thiserror::Error as ThisError;
4041
use thread_local::ThreadLocal;
4142

@@ -44,7 +45,7 @@ use thread_local::ThreadLocal;
4445

4546
/// Errors that can occur during generation of the density map
4647
#[derive(Debug, ThisError)]
47-
pub enum DensityMapError<R: Real> {
48+
pub enum DensityMapError<R: Scalar> {
4849
/// Indicates that domain for the density map is inconsistent or degenerate
4950
///
5051
/// For the density map computation the user specified domain is shrunk ensuring that all
@@ -225,7 +226,7 @@ pub fn parallel_compute_particle_densities<I: Index, R: Real>(
225226
/// The density map contains values for all points of the background grid where the density is not
226227
/// trivially zero (which is the case when a point is outside the compact support of any particles).
227228
#[derive(Clone, Debug)]
228-
pub enum DensityMap<'a, I: Index, R: Real> {
229+
pub enum DensityMap<'a, I: Scalar + Eq + Hash, R: Scalar> {
229230
Standard(MapType<I, R>),
230231
DashMap(ReadDashMap<I, R, HashState>),
231232
Dense(Cow<'a, [R]>),

splashsurf_lib/src/halfedge_mesh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
use crate::mesh::{Mesh3d, TriMesh3d, TriMesh3dExt};
66
use crate::{Real, SetType, profile};
7-
use nalgebra::Vector3;
7+
use nalgebra::{Scalar, Vector3};
88
use rayon::prelude::*;
99
use thiserror::Error as ThisError;
1010

@@ -54,7 +54,7 @@ impl HalfEdge {
5454
/// [`is_valid_vertex`](HalfEdgeTriMesh::is_valid_vertex)/[`is_valid_triangle`](HalfEdgeTriMesh::is_valid_triangle)/[`is_valid_half_edge`](HalfEdgeTriMesh::is_valid_half_edge)
5555
/// methods.
5656
#[derive(Clone, Debug, Default)]
57-
pub struct HalfEdgeTriMesh<R: Real> {
57+
pub struct HalfEdgeTriMesh<R: Scalar> {
5858
/// All vertices in the mesh
5959
pub vertices: Vec<Vector3<R>>,
6060
/// All triangles in the mesh

splashsurf_lib/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use log::info;
2727
/// Re-export the version of `nalgebra` used by this crate
2828
pub use nalgebra;
29+
use nalgebra::Scalar;
2930
use nalgebra::Vector3;
3031
use std::borrow::Cow;
3132
use std::hash::Hash;
@@ -154,7 +155,7 @@ impl Default for GridDecompositionParameters {
154155

155156
/// Parameters for the surface reconstruction
156157
#[derive(Clone, Debug)]
157-
pub struct Parameters<R: Real> {
158+
pub struct Parameters<R: Scalar> {
158159
/// Radius per particle (used to calculate the particle volume)
159160
pub particle_radius: R,
160161
/// Rest density of the fluid
@@ -237,7 +238,7 @@ impl<R: Real> Parameters<R> {
237238

238239
/// Result data returned when the surface reconstruction was successful
239240
#[derive(Clone, Debug)]
240-
pub struct SurfaceReconstruction<I: Index, R: Real> {
241+
pub struct SurfaceReconstruction<I: Scalar, R: Scalar + Send + Default> {
241242
/// Background grid that was used as a basis for generating the density map for marching cubes
242243
pub grid: UniformGrid<I, R>,
243244
/// Per particle densities (contains only data of particles inside the domain)

splashsurf_lib/src/mesh.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! - [`IntoVtkUnstructuredGridPiece`] to convert basic meshes and meshes with attached attributes to the
1616
//! - [`IntoVtkDataSet`] for all meshes implementing [`IntoVtkUnstructuredGridPiece`] to directly save a mesh as a VTK file
1717
18-
use crate::{Aabb3d, MapType, Real, RealConvert, new_map, profile};
18+
use crate::{Aabb3d, MapType, Real, RealConvert, Scalar, new_map, profile};
1919
use bytemuck_derive::{Pod, Zeroable};
2020
use nalgebra::{Unit, Vector3};
2121
use rayon::prelude::*;
@@ -159,7 +159,7 @@ impl<R: Real> TriMesh3dExt<R> for TriMesh3d<R> {
159159
///
160160
/// The attribute data can be owned or borrowed.
161161
#[derive(Clone, Debug)]
162-
pub struct MeshAttribute<'a, R: Real> {
162+
pub struct MeshAttribute<'a, R: Scalar> {
163163
/// Name of the attribute
164164
pub name: String,
165165
/// Data of the attribute
@@ -174,7 +174,7 @@ pub type OwnedMeshAttribute<R> = MeshAttribute<'static, R>;
174174
/// Each value in the data-set is associated to a point or cell of the mesh.
175175
/// Data can be owned or borrowed.
176176
#[derive(Clone, Debug)]
177-
pub enum AttributeData<'a, R: Real> {
177+
pub enum AttributeData<'a, R: Scalar> {
178178
ScalarU64(Cow<'a, [u64]>),
179179
ScalarReal(Cow<'a, [R]>),
180180
Vector3Real(Cow<'a, [Vector3<R>]>),
@@ -185,7 +185,7 @@ pub type OwnedAttributeData<R> = AttributeData<'static, R>;
185185

186186
/// A triangle (surface) mesh in 3D
187187
#[derive(Clone, Debug, Default)]
188-
pub struct TriMesh3d<R: Real> {
188+
pub struct TriMesh3d<R: Scalar> {
189189
/// Coordinates of all vertices of the mesh
190190
pub vertices: Vec<Vector3<R>>,
191191
/// The triangles of the mesh identified by their vertex indices
@@ -229,7 +229,7 @@ impl TriangleOrQuadCell {
229229

230230
/// A surface mesh in 3D containing cells representing either triangles or quadrilaterals
231231
#[derive(Clone, Debug, Default)]
232-
pub struct MixedTriQuadMesh3d<R: Real> {
232+
pub struct MixedTriQuadMesh3d<R: Scalar> {
233233
/// Coordinates of all vertices of the mesh
234234
pub vertices: Vec<Vector3<R>>,
235235
/// All triangle and quad cells of the mesh
@@ -238,7 +238,7 @@ pub struct MixedTriQuadMesh3d<R: Real> {
238238

239239
/// A hexahedral (volumetric) mesh in 3D
240240
#[derive(Clone, Debug, Default)]
241-
pub struct HexMesh3d<R: Real> {
241+
pub struct HexMesh3d<R: Scalar> {
242242
/// Coordinates of all vertices of the mesh
243243
pub vertices: Vec<Vector3<R>>,
244244
/// The hexahedral cells of the mesh identified by their vertex indices
@@ -247,7 +247,7 @@ pub struct HexMesh3d<R: Real> {
247247

248248
/// A point cloud in 3D
249249
#[derive(Clone, Debug, Default)]
250-
pub struct PointCloud3d<R: Real> {
250+
pub struct PointCloud3d<R: Scalar> {
251251
/// Coordinates of all points in the point cloud
252252
points: Vec<Vector3<R>>,
253253
/// Indices of the points (for `CellConnectivity`)
@@ -330,7 +330,7 @@ where
330330
}
331331
}
332332

333-
/// Removes all cells from the mesh that are completely outside of the given AABB and clamps the remaining cells to the boundary
333+
/// Removes all cells from the mesh that are completely outside the given AABB and clamps the remaining cells to the boundary
334334
fn par_clamp_with_aabb(
335335
&self,
336336
aabb: &Aabb3d<R>,

splashsurf_lib/src/uniform_grid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{Aabb3d, Index, Real};
55
use bitflags::bitflags;
66
use itertools::iproduct;
77
use log::trace;
8-
use nalgebra::Vector3;
8+
use nalgebra::{Scalar, Vector3};
99
use num_traits::Bounded;
1010
use std::iter::Iterator;
1111
use thiserror::Error as ThisError;
@@ -107,7 +107,7 @@ pub type UniformGrid<I, R> = UniformCartesianCubeGrid3d<I, R>;
107107

108108
/// Helper type for connectivity information on a 3D cartesian grid based on uniform cubes
109109
///
110-
/// This type represents a virtual or implicit three dimensional cartesian grid in based on uniform cubes.
110+
/// This type represents a virtual or implicit three-dimensional cartesian grid in based on uniform cubes.
111111
/// It provides helper functions to access connectivity of points (vertices), edges and cells on
112112
/// the virtual grid.
113113
///
@@ -127,7 +127,7 @@ pub type UniformGrid<I, R> = UniformCartesianCubeGrid3d<I, R>;
127127
/// functions respectively. These functions check if the specified indices are in the valid index range
128128
/// of the grid (as computed during construction based on the extents of the grid).
129129
#[derive(Clone, PartialEq, Debug)]
130-
pub struct UniformCartesianCubeGrid3d<I: Index, R: Real> {
130+
pub struct UniformCartesianCubeGrid3d<I: Scalar, R: Scalar> {
131131
/// AABB of the grid. Note that the grid may extend beyond the max coordinate of the AABB by less than the `cell_size`.
132132
aabb: Aabb3d<R>,
133133
/// The edge length of the cubes in the grid

splashsurf_lib/src/workspace.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Workspace for reusing allocated memory between multiple surface reconstructions
22
3-
use crate::Real;
3+
use crate::{Real, Scalar};
44
use nalgebra::Vector3;
55
use std::cell::RefCell;
66
use std::fmt;
@@ -9,7 +9,7 @@ use thread_local::ThreadLocal;
99

1010
/// Collection of all thread local workspaces used to reduce allocations on subsequent surface reconstructions
1111
#[derive(Default)]
12-
pub struct ReconstructionWorkspace<R: Real> {
12+
pub struct ReconstructionWorkspace<R: Scalar + Send> {
1313
/// Temporary storage for storing a filtered set of the user provided particles
1414
filtered_particles: Vec<Vector3<R>>,
1515
local_workspaces: ThreadLocal<RefCell<LocalReconstructionWorkspace<R>>>,
@@ -31,22 +31,22 @@ impl<R: Real> ReconstructionWorkspace<R> {
3131
}
3232
}
3333

34-
impl<R: Real> Clone for ReconstructionWorkspace<R> {
34+
impl<R: Scalar + Send + Default> Clone for ReconstructionWorkspace<R> {
3535
/// Returns a new default workspace without any allocated memory
3636
fn clone(&self) -> Self {
3737
ReconstructionWorkspace::default()
3838
}
3939
}
4040

41-
impl<R: Real> Debug for ReconstructionWorkspace<R> {
41+
impl<R: Scalar + Send> Debug for ReconstructionWorkspace<R> {
4242
/// Only print the name of type to the formatter
4343
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
4444
f.debug_struct("ReconstructionWorkspace").finish()
4545
}
4646
}
4747

4848
/// Workspace used by [`reconstruct_surface_inplace`] internally to re-use allocated memory
49-
pub(crate) struct LocalReconstructionWorkspace<R: Real> {
49+
pub(crate) struct LocalReconstructionWorkspace<R: Scalar> {
5050
/// Storage for per particle neighbor lists
5151
pub particle_neighbor_lists: Vec<Vec<usize>>,
5252
/// Storage for per particle densities

0 commit comments

Comments
 (0)