From d136a56a904395f632d1e220cb4cb194c348299a Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Tue, 11 Oct 2022 13:37:43 +0200 Subject: [PATCH] [clippy] Use clamp in camera.rs Rationnal: ``` warning: clamp-like pattern without using clamp function --> src/game/camera.rs:68:17 | 68 | rect.x.max(min.x).min(max.x), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `rect.x.clamp(min.x, max.x)` | = note: clamp will panic if max < min, min.is_nan(), or max.is_nan() = note: clamp returns NaN if the input is NaN = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp = note: `#[warn(clippy::manual_clamp)]` on by default warning: clamp-like pattern without using clamp function --> src/game/camera.rs:69:17 | 69 | rect.y.max(min.y).min(max.y), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with clamp: `rect.y.clamp(min.y, max.y)` | = note: clamp will panic if max < min, min.is_nan(), or max.is_nan() = note: clamp returns NaN if the input is NaN = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp ``` --- src/game/camera.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/camera.rs b/src/game/camera.rs index 0bcc1a29cc..b6848d111c 100644 --- a/src/game/camera.rs +++ b/src/game/camera.rs @@ -65,8 +65,8 @@ impl GameCamera { let max = min + Vec2::new(playable.w, playable.h); self.player_rects.push(Rect::new( - rect.x.max(min.x).min(max.x), - rect.y.max(min.y).min(max.y), + rect.x.clamp(min.x, max.x), + rect.y.clamp(min.y, max.y), rect.w, rect.h, ));