From 8e3944d5df30bb587ac8941eb6eeb042bcedab25 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 24 Mar 2025 16:10:38 -0400 Subject: [PATCH] clippy --- src/blur.rs | 2 +- src/imgdata.rs | 20 ++++++++++---------- src/model.rs | 10 +++++----- src/palette.rs | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/blur.rs b/src/blur.rs index 1467183..64e5b09 100644 --- a/src/blur.rs +++ b/src/blur.rs @@ -37,7 +37,7 @@ impl Blur { } // Approximate 1D Gaussian filter of standard deviation sigma with N box filter passes. Each element in the output array contains the radius of the box filter for the corresponding pass. - fn boxes_for_gaussian(sigma: f32) -> ([usize; N]) { + fn boxes_for_gaussian(sigma: f32) -> [usize; N] { let w_ideal = (12.0 * sigma * sigma / N as f32 + 1.0).sqrt(); let mut w = w_ideal as usize; w -= 1 - (w & 1); diff --git a/src/imgdata.rs b/src/imgdata.rs index 811363c..ba4b447 100644 --- a/src/imgdata.rs +++ b/src/imgdata.rs @@ -32,9 +32,9 @@ impl ThinGridData { #[allow(dead_code)] pub fn new_from_grid_vec(in_grids: Vec) -> Vec { - return in_grids.iter().map(|grid|{ + in_grids.iter().map(|grid|{ Self::new_from_grid(grid) - }).collect(); + }).collect() } // from grid.rs (needed in image gen) @@ -60,12 +60,12 @@ impl ThinGridData { pub fn size_of(&self) -> usize { let mut output: usize = 0; - output = output + std::mem::size_of_val(&self.width); - output = output + std::mem::size_of_val(&self.height); + output += std::mem::size_of_val(&self.width); + output += std::mem::size_of_val(&self.height); for i in self.data.iter() { - output = output + std::mem::size_of_val(&i); + output += std::mem::size_of_val(&i); } - return output; + output } } @@ -97,12 +97,12 @@ impl ImgData { pub fn size_of(&self) -> usize { let mut output: usize = 0; - output = output + std::mem::size_of_val(&self.iteration); - output = output + std::mem::size_of_val(&self.palette); + output += std::mem::size_of_val(&self.iteration); + output += std::mem::size_of_val(&self.palette); for grid in self.grids.iter() { - output = output + grid.size_of(); + output += grid.size_of(); } - return output; + output } #[inline] diff --git a/src/model.rs b/src/model.rs index 862f74e..f158222 100644 --- a/src/model.rs +++ b/src/model.rs @@ -132,7 +132,7 @@ impl Model { self.save_image_data(); let agents_tick_elapsed: f64 = agents_tick_time.elapsed().as_millis() as f64; - let ms_per_agent: f64 = (agents_tick_elapsed as f64) / (agents_num as f64); + let ms_per_agent: f64 = agents_tick_elapsed / (agents_num as f64); time_per_agent_list.push(ms_per_agent); time_per_step_list.push(agents_tick_elapsed); @@ -149,9 +149,9 @@ impl Model { pb.finish(); let avg_per_step: f64 = - time_per_step_list.iter().sum::() as f64 / time_per_step_list.len() as f64; + time_per_step_list.iter().sum::() / time_per_step_list.len() as f64; let avg_per_agent: f64 = - time_per_agent_list.iter().sum::() as f64 / time_per_agent_list.len() as f64; + time_per_agent_list.iter().sum::() / time_per_agent_list.len() as f64; println!( "Average time per step: {}ms\nAverage time per agent: {}ms", avg_per_step, avg_per_agent @@ -159,7 +159,7 @@ impl Model { } fn size_of_imgdata_vec(&self) -> usize { - return (self.img_data_vec[0].size_of() as usize) * (self.img_data_vec.len() as usize); + self.img_data_vec[0].size_of() * self.img_data_vec.len() } fn save_image_data(&mut self) { @@ -200,7 +200,7 @@ impl Model { pb.finish(); */ - (&self.img_data_vec) + self.img_data_vec .par_iter() .progress_with(pb) .for_each(|img| { diff --git a/src/palette.rs b/src/palette.rs index 8c6006c..8187c5f 100644 --- a/src/palette.rs +++ b/src/palette.rs @@ -15,7 +15,7 @@ pub fn random_palette() -> Palette { const fn hex_to_color(c: usize) -> image::Rgb { let r = (c >> 16) & 0xff; let g = (c >> 8) & 0xff; - let b = (c >> 0) & 0xff; + let b = c & 0xff; image::Rgb::([r as u8, g as u8, b as u8]) }