Skip to content

Commit

Permalink
Apply clippy --fix
Browse files Browse the repository at this point in the history
  • Loading branch information
w1th0utnam3 committed Feb 5, 2025
1 parent b7b2001 commit 47d4556
Show file tree
Hide file tree
Showing 34 changed files with 273 additions and 321 deletions.
2 changes: 1 addition & 1 deletion splashsurf/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ unsafe impl<A: GlobalAlloc> GlobalAlloc for CountingAllocator<A> {
self.peak_allocation
.fetch_max(current_allocation, Ordering::AcqRel);
}
return ret;
ret
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
Expand Down
12 changes: 5 additions & 7 deletions splashsurf/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,11 @@ fn convert_mesh(cmd_args: &ConvertSubcommandArgs) -> Result<(), anyhow::Error> {

/// Returns an error if the file already exists but overwrite is disabled
fn overwrite_check(cmd_args: &ConvertSubcommandArgs) -> Result<(), anyhow::Error> {
if !cmd_args.overwrite {
if cmd_args.output_file.exists() {
return Err(anyhow!(
"Aborting: Output file \"{}\" already exists. Use overwrite flag to ignore this.",
cmd_args.output_file.display()
));
}
if !cmd_args.overwrite && cmd_args.output_file.exists() {
return Err(anyhow!(
"Aborting: Output file \"{}\" already exists. Use overwrite flag to ignore this.",
cmd_args.output_file.display()
));
}

Ok(())
Expand Down
26 changes: 10 additions & 16 deletions splashsurf/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@ pub struct FormatParameters {
}

/// File format parameters for input files
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Default)]
pub struct InputFormatParameters {}

impl Default for InputFormatParameters {
fn default() -> Self {
Self {}
}
}

/// File format parameters for output files
#[derive(Clone, Debug)]
pub struct OutputFormatParameters {
Expand Down Expand Up @@ -107,7 +101,7 @@ pub fn read_particle_positions_with_attributes<R: Real, P: AsRef<Path>>(

let vtk_pieces = VtkFile::load_file(input_file)
.map(|f| f.into_pieces())
.with_context(|| format!("Failed to load particle positions from file"))?;
.with_context(|| "Failed to load particle positions from file".to_string())?;

if vtk_pieces.len() > 1 {
warn!("VTK file contains more than one \"piece\". Only the first one will be loaded.");
Expand Down Expand Up @@ -176,13 +170,13 @@ pub fn write_particle_positions<R: Real, P: AsRef<Path>>(
.ok_or(anyhow!("Invalid extension of output file"))?;

match extension.to_lowercase().as_str() {
"vtk" => vtk_format::particles_to_vtk(particles, &output_file),
"vtk" => vtk_format::particles_to_vtk(particles, output_file),
"bgeo" => bgeo_format::particles_to_bgeo(
particles,
&output_file,
output_file,
format_params.enable_compression,
),
"json" => json_format::particles_to_json(particles, &output_file),
"json" => json_format::particles_to_json(particles, output_file),
_ => Err(anyhow!(
"Unsupported file format extension \"{}\" for writing particles",
extension
Expand Down Expand Up @@ -214,8 +208,8 @@ pub fn read_surface_mesh<R: Real, P: AsRef<Path>>(
.ok_or(anyhow!("Invalid extension of input file"))?;

match extension.to_lowercase().as_str() {
"vtk" => vtk_format::surface_mesh_from_vtk(&input_file),
"ply" => ply_format::surface_mesh_from_ply(&input_file),
"vtk" => vtk_format::surface_mesh_from_vtk(input_file),
"ply" => ply_format::surface_mesh_from_ply(input_file),
_ => Err(anyhow!(
"Unsupported file format extension \"{}\" for reading surface meshes",
extension
Expand Down Expand Up @@ -261,9 +255,9 @@ where
.ok_or(anyhow!("Invalid extension of output file"))?;

match extension.to_lowercase().as_str() {
"vtk" => vtk_format::write_vtk(mesh, &output_file, "mesh"),
"ply" => ply_format::mesh_to_ply(mesh, &output_file),
"obj" => obj_format::mesh_to_obj(mesh, &output_file),
"vtk" => vtk_format::write_vtk(mesh, output_file, "mesh"),
"ply" => ply_format::mesh_to_ply(mesh, output_file),
"obj" => obj_format::mesh_to_obj(mesh, output_file),
_ => Err(anyhow!(
"Unsupported file format extension \"{}\"",
extension,
Expand Down
12 changes: 6 additions & 6 deletions splashsurf/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ impl<T: Write + Send> ProgressHandler<T> {
fn handle<F: FnOnce(&mut Self) -> R, R>(&mut self, inner_function: F) -> R {
let handle = get_progress_bar();

return match handle {
Some(pb) => pb.suspend(|| return inner_function(self)),
match handle {
Some(pb) => pb.suspend(|| inner_function(self)),
None => inner_function(self),
};
}
}

/// Create a new instance of "Self"
pub fn new(pipe: T) -> Self {
return Self(pipe);
Self(pipe)
}
}

Expand All @@ -44,12 +44,12 @@ impl<T: Write + Send + 'static> ProgressHandler<T> {
impl<T: Write + Send> Write for ProgressHandler<T> {
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
return self.handle(|this| this.0.write(buf));
self.handle(|this| this.0.write(buf))
}

#[inline]
fn flush(&mut self) -> std::io::Result<()> {
return self.handle(|this| this.0.flush());
self.handle(|this| this.0.flush())
}
}

Expand Down
2 changes: 1 addition & 1 deletion splashsurf/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn run_splashsurf() -> Result<(), anyhow::Error> {
splashsurf_lib::profiling::write_to_string()
.unwrap()
.split("\n")
.filter(|l| l.len() > 0)
.filter(|l| !l.is_empty())
.for_each(|l| info!("{}", l));

// Print memory stats if available
Expand Down
33 changes: 18 additions & 15 deletions splashsurf/src/reconstruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,30 @@ pub fn reconstruct_subcommand(cmd_args: &ReconstructSubcommandArgs) -> Result<()
path.input_file.display()
)
})
.map_err(|err| {
.inspect_err(|err| {
// Already log the error in case there are multiple errors
logging::log_error(&err);
err
logging::log_error(err);
})
.and_then(|_| {
logging::get_progress_bar().map(|pb| pb.inc(1));
Ok(())
.map(|_| {
if let Some(pb) = logging::get_progress_bar() {
pb.inc(1)
}
})
})
} else {
paths.iter().try_for_each(|path| {
reconstruction_pipeline(path, &args).and_then(|_| {
logging::get_progress_bar().map(|pb| pb.inc(1));
Ok(())
reconstruction_pipeline(path, &args).map(|_| {
if let Some(pb) = logging::get_progress_bar() {
pb.inc(1)
}
})
})
};

if paths.len() > 1 {
logging::get_progress_bar().map(|pb| pb.finish());
if let Some(pb) = logging::get_progress_bar() {
pb.finish()
}
logging::set_progress_bar(None);
}

Expand Down Expand Up @@ -922,7 +925,7 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
.parent()
// Add a trailing separator if the parent is non-empty
.map(|p| p.join(""))
.unwrap_or_else(PathBuf::new);
.unwrap_or_default();
let output_filename = format!(
"raw_{}",
paths.output_file.file_name().unwrap().to_string_lossy()
Expand Down Expand Up @@ -1028,7 +1031,7 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
// Global neighborhood search
let nl = reconstruction
.particle_neighbors()
.map(|nl| Cow::Borrowed(nl))
.map(Cow::Borrowed)
.unwrap_or_else(||
{
let search_radius = params.compact_support_radius;
Expand Down Expand Up @@ -1059,8 +1062,8 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
.map(|j| {
let dist =
(particle_positions[i] - particle_positions[j]).norm_squared();
let weight = R::one() - (dist / squared_r).clamp(R::zero(), R::one());
return weight;

R::one() - (dist / squared_r).clamp(R::zero(), R::one())
})
.fold(R::zero(), R::add)
})
Expand All @@ -1073,7 +1076,7 @@ pub(crate) fn reconstruction_pipeline_generic<I: Index, R: Real>(
.expect("interpolator is required")
.interpolate_scalar_quantity(
weighted_ncounts.as_slice(),
&mesh_with_data.vertices(),
mesh_with_data.vertices(),
true,
)
};
Expand Down
12 changes: 6 additions & 6 deletions splashsurf_lib/benches/benches/bench_neighborhood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ static COMPACT_SUPPORT_RADIUS: f64 = 4.0 * PARTICLE_RADIUS;
//static NUM_PARTICLES: Option<usize> = Some(800);
static NUM_PARTICLES: Option<usize> = None;

static PARTICLE_FILE: &'static str = "../data/bunny_frame_14_7705_particles.vtk";
static PARTICLE_FILE: &str = "../data/bunny_frame_14_7705_particles.vtk";

fn particle_subset(particle_positions: &[Vector3<f32>]) -> &[Vector3<f32>] {
if let Some(n_particles) = NUM_PARTICLES.clone() {
if let Some(n_particles) = NUM_PARTICLES {
&particle_positions[0..n_particles]
} else {
&particle_positions[..]
particle_positions
}
}

Expand All @@ -35,7 +35,7 @@ pub fn neighborhood_search_naive(c: &mut Criterion) {
b.iter(|| {
neighborhood_lists.clear();
neighborhood_search::neighborhood_search_naive(
&particle_positions,
particle_positions,
COMPACT_SUPPORT_RADIUS as f32,
&mut neighborhood_lists,
);
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn neighborhood_search_spatial_hashing(c: &mut Criterion) {
neighborhood_lists.clear();
neighborhood_search::neighborhood_search_spatial_hashing::<i32, f32>(
&domain,
&particle_positions,
particle_positions,
COMPACT_SUPPORT_RADIUS as f32,
&mut neighborhood_lists,
);
Expand Down Expand Up @@ -93,7 +93,7 @@ pub fn neighborhood_search_spatial_hashing_parallel(c: &mut Criterion) {
neighborhood_lists.clear();
neighborhood_search::neighborhood_search_spatial_hashing_parallel::<i32, f32>(
&domain,
&particle_positions,
particle_positions,
COMPACT_SUPPORT_RADIUS as f32,
&mut neighborhood_lists,
);
Expand Down
6 changes: 2 additions & 4 deletions splashsurf_lib/benches/benches/bench_subdomain_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn parameters_canyon() -> Parameters<f32> {
let compact_support_radius = 4.0 * particle_radius;
let cube_size = 1.5 * particle_radius;

let parameters = Parameters {
Parameters {
particle_radius,
rest_density: 1000.0,
compact_support_radius,
Expand All @@ -27,9 +27,7 @@ fn parameters_canyon() -> Parameters<f32> {
},
)),
global_neighborhood_list: false,
};

parameters
}
}

pub fn grid_canyon(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion splashsurf_lib/examples/minimal_levelset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn marching_cubes<R: Real, L: MarchingCubesLevelSet<R>>(
let vertex_index = *edge_to_vertex.entry(edge).or_insert_with(|| {
let vertex_index = vertices.len();

let origin_coords = grid.point_coordinates(&edge.origin());
let origin_coords = grid.point_coordinates(edge.origin());
let target_coords = grid.point_coordinates(&edge.target());

let origin_value = level_set.evaluate(&origin_coords);
Expand Down
6 changes: 3 additions & 3 deletions splashsurf_lib/src/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ where
if points.is_empty() {
Self::zeros()
} else if points.len() == 1 {
Self::from_point(points[0].clone())
Self::from_point(points[0])
} else {
let initial_aabb = Self::from_point(points[0].clone());
let initial_aabb = Self::from_point(points[0]);
points[1..]
.par_iter()
.fold(
Expand Down Expand Up @@ -73,7 +73,7 @@ where
#[inline(always)]
pub fn from_point(point: SVector<R, D>) -> Self {
Self {
min: point.clone(),
min: point,
max: point,
}
}
Expand Down
Loading

0 comments on commit 47d4556

Please sign in to comment.