Fix issues found by `cargo clippy`, including bugs

This commit is contained in:
Matthew Gordon 2024-11-22 20:32:15 -04:00
parent a4503c3dbf
commit e7180e57bf
3 changed files with 12 additions and 17 deletions

View File

@ -37,7 +37,7 @@ struct Camera {
} }
impl Camera { impl Camera {
fn new(device: &wgpu::Device, viewport_aspect_ratio: f32) -> Self { fn new(viewport_aspect_ratio: f32) -> Self {
let projection_matrix = glam::Mat4::perspective_rh( let projection_matrix = glam::Mat4::perspective_rh(
std::f32::consts::FRAC_PI_4, std::f32::consts::FRAC_PI_4,
viewport_aspect_ratio, viewport_aspect_ratio,
@ -182,10 +182,7 @@ impl DemRenderer {
) )
}; };
let camera = Camera::new( let camera = Camera::new(surface_config.width as f32 / surface_config.height as f32);
device,
surface_config.width as f32 / surface_config.height as f32,
);
let mut uniforms = UniformBufferManager::new(device); let mut uniforms = UniformBufferManager::new(device);
uniforms.set_dem_texture_size(dem_texture_size); uniforms.set_dem_texture_size(dem_texture_size);
@ -329,7 +326,7 @@ impl DemRenderer {
fn get_max_dem_dimension(&self) -> f32 { fn get_max_dem_dimension(&self) -> f32 {
let dem = &self.source; let dem = &self.source;
(dem.x_max - dem.x_min) (dem.x_max - dem.x_min)
.max(dem.y_max - dem.y_max) .max(dem.y_max - dem.y_min)
.max(dem.z_max - dem.x_min) .max(dem.z_max - dem.x_min)
} }

View File

@ -200,5 +200,5 @@ impl MvuApp<Model> for App {
fn open_test_file(file_path: PathBuf, model: Rc<Model>) -> Rc<Model> { fn open_test_file(file_path: PathBuf, model: Rc<Model>) -> Rc<Model> {
let dem = Some(Rc::new(raster::Dem::load_from_image(&file_path))); let dem = Some(Rc::new(raster::Dem::load_from_image(&file_path)));
Rc::new(Model { dem }) Rc::new(Model { dem, ..*model })
} }

View File

@ -1,7 +1,4 @@
use { use std::{fs::File, path::PathBuf};
std::{fs::File, path::PathBuf},
tiff,
};
#[derive(Clone)] #[derive(Clone)]
pub struct Dem { pub struct Dem {
@ -63,9 +60,9 @@ fn round_bound(v: u32) -> u32 {
impl DemBvh { impl DemBvh {
fn new(dem: &Dem) -> DemBvh { fn new(dem: &Dem) -> DemBvh {
let mut layers = vec![create_first_dembvh_layer(&dem)]; let mut layers = vec![create_first_dembvh_layer(dem)];
while layers.last().unwrap().size > 1 { while layers.last().unwrap().size > 1 {
layers.push(create_next_dembvh_layer(&layers.last().unwrap())); layers.push(create_next_dembvh_layer(layers.last().unwrap()));
} }
DemBvh { layers } DemBvh { layers }
} }
@ -181,10 +178,11 @@ impl Dem {
let x_max = 500.0; let x_max = 500.0;
let y_min = -500.0; let y_min = -500.0;
let y_max = 500.0; let y_max = 500.0;
let (z_min, z_max) = f32_values[1..].iter().fold( let (z_min, z_max) = f32_values[1..]
(f32_values[0], f32_values[0]), .iter()
|(min, max), elem| (min.min(*elem), max.max(*elem)), .fold((f32_values[0], f32_values[0]), |(min, max), elem| {
); (min.min(*elem), max.max(*elem))
});
let grid = f32_values let grid = f32_values
.iter() .iter()
.map(|v| normalized_f32_to_u16(normalize_f32(*v, z_min, z_max))) .map(|v| normalized_f32_to_u16(normalize_f32(*v, z_min, z_max)))