From 0e321d0fd48ad953fc564341ecc52dadd51ff146 Mon Sep 17 00:00:00 2001 From: terrarier2111 Date: Sat, 25 May 2024 10:28:15 +0200 Subject: [PATCH] Fix clippy warnings --- src/model/mod.rs | 5 ++--- src/render/mod.rs | 2 +- src/screen/background.rs | 2 +- src/server/mod.rs | 8 ++------ src/ui/logo.rs | 3 ++- src/ui/mod.rs | 4 ++-- src/world/biome.rs | 4 ++-- src/world/mod.rs | 2 +- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/model/mod.rs b/src/model/mod.rs index d2303069..05ef02d5 100644 --- a/src/model/mod.rs +++ b/src/model/mod.rs @@ -1050,7 +1050,6 @@ fn calculate_biome( z: i32, img: &image::DynamicImage, ) -> (u8, u8, u8) { - use std::cmp::{max, min}; let mut count = 0; let mut r = 0; let mut g = 0; @@ -1062,8 +1061,8 @@ fn calculate_biome( let ix = color_index & 0xFF; let iy = color_index >> 8; - let ix = min(max(ix, 0), 255); - let iy = min(max(iy, 0), 255); + let ix = ix.clamp(0, 255); + let iy = iy.clamp(0, 255); let col = img.get_pixel(ix as u32, iy as u32); let col = bi.process_color(col); diff --git a/src/render/mod.rs b/src/render/mod.rs index 6e8dfc9d..5dbaeb62 100644 --- a/src/render/mod.rs +++ b/src/render/mod.rs @@ -1693,7 +1693,7 @@ impl TextureManager { // work with the new name let mut old = self.textures.remove(&old_name).unwrap(); old.name = format!("leafish-dynamic:{}", name); - t.name = old.name.clone(); + t.name.clone_from(&old.name); self.textures .insert(format!("leafish-dynamic:{}", name), old); t diff --git a/src/screen/background.rs b/src/screen/background.rs index 7fede16d..b612a7b3 100644 --- a/src/screen/background.rs +++ b/src/screen/background.rs @@ -41,7 +41,7 @@ impl Screen for Background { ui_container: &mut Container, ) { let path = self.settings.get_string(StringSetting::BackgroundImage); - self.last_path = path.clone(); + self.last_path.clone_from(&path); let background = if Renderer::get_texture_optional(renderer.get_textures_ref(), &path).is_some() { Some( diff --git a/src/server/mod.rs b/src/server/mod.rs index cf59d1bf..cec93152 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1204,11 +1204,7 @@ impl Server { offset = prev_offset + (offset - prev_offset) / 3.0; offset = 1.0 - ((offset * PI * 2.0).cos() * 2.0 + 0.2); - if offset > 1.0 { - offset = 1.0; - } else if offset < 0.0 { - offset = 0.0; - } + offset = offset.clamp(0.0, 1.0); offset = 1.0 - offset; offset * 0.8 + 0.2 } @@ -1703,7 +1699,7 @@ impl Server { stack, } }); - top_inventory.write().cursor = item.clone(); + top_inventory.write().cursor.clone_from(&item); self.inventory_context.write().set_cursor(item); self.hud_context .read() diff --git a/src/ui/logo.rs b/src/ui/logo.rs index ae051a75..f944b022 100644 --- a/src/ui/logo.rs +++ b/src/ui/logo.rs @@ -146,7 +146,8 @@ impl Logo { let mut text = self.text.borrow_mut(); if self.text_index != text_index { self.text_index = text_index; - text.text = self.text_strings[text_index as usize].clone(); + text.text + .clone_from(&self.text_strings[text_index as usize]); let width = (renderer.ui.lock().size_of_string(&text.text) + 2.0) * text.scale_x; self.text_base_scale = 300.0 / width; if self.text_base_scale > 1.0 { diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b896d8a2..89e2d78a 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -881,7 +881,7 @@ impl UIElement for Image { element.a = self.colour.3; self.data.extend_from_slice(&element.bytes(width, height)); self.super_draw(renderer, r, sw, sh, width, height, delta); - self.last_texture = self.texture.clone(); + self.last_texture.clone_from(&self.texture); self.last_colour = self.colour; self.last_texture_coords = self.texture_coords; } @@ -1040,7 +1040,7 @@ impl UIElement for Text { self.data.extend_from_slice(&text.bytes(width, height)); self.super_draw(renderer, r, sw, sh, width, height, delta); - self.last_text = self.text.clone(); + self.last_text.clone_from(&self.text); self.last_colour = self.colour; self.last_scale_x = self.scale_x; self.last_scale_y = self.scale_y; diff --git a/src/world/biome.rs b/src/world/biome.rs index ea3e9991..de231382 100644 --- a/src/world/biome.rs +++ b/src/world/biome.rs @@ -22,8 +22,8 @@ impl Biome { } pub fn get_color_index(self) -> usize { - let t = (self.temperature as f64 / 100f64).min(1.0).max(0.0); - let m = (self.moisture as f64 / 100f64).min(1.0).max(0.0); + let t = (self.temperature as f64 / 100f64).clamp(0.0, 1.0); + let m = (self.moisture as f64 / 100f64).clamp(0.0, 1.0); (((1.0 - t) * 255.0) as usize) | ((((1.0 - (m * t)) * 255.0) as usize) << 8) } diff --git a/src/world/mod.rs b/src/world/mod.rs index 79d37188..3f9f60e8 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -1483,7 +1483,7 @@ impl Command for UpdateSignInfoCmd { .as_mut() .and_then(|entity| entity.get_mut::()) { - info.lines = self.0.clone(); + info.lines.clone_from(&self.0); info.dirty = true; } }