From 0264e4234baf496871921bf244168e9c33e7bfc3 Mon Sep 17 00:00:00 2001 From: e-dt Date: Sat, 1 Jan 2022 20:55:11 +1100 Subject: [PATCH 1/2] fixed unneeded as conversions --- src/apr.rs | 12 ++++++------ src/board.rs | 4 ++-- src/main.rs | 4 ++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/apr.rs b/src/apr.rs index 6396fbc..9564f65 100644 --- a/src/apr.rs +++ b/src/apr.rs @@ -27,8 +27,8 @@ pub fn make_grid(ctx: &mut Context, r: u8, c: u8, board: &[Vec]) -> GameResu builder.rectangle( DrawMode::fill(), graphics::Rect { - x: board::START_X + (board::BOARD_SQUARE_SIZE * col as f32), - y: board::START_Y + (board::BOARD_SQUARE_SIZE * row as f32), + x: board::START_X + (board::BOARD_SQUARE_SIZE * f32::from(col)), + y: board::START_Y + (board::BOARD_SQUARE_SIZE * f32::from(row)), w: board::BOARD_SQUARE_SIZE, h: board::BOARD_SQUARE_SIZE, }, @@ -144,8 +144,8 @@ impl EventHandler for Apr { if mouse::button_pressed(ctx, MouseButton::Left) && !self.dragging { let (posx, posy) = self.board.closest_square_coords(posn.x, posn.y); if posx == x && posy == y { - let x = board::START_X + board::BOARD_SQUARE_SIZE * (x as f32); - let y = board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32); + let x = board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x); + let y = board::START_Y + board::BOARD_SQUARE_SIZE * f32::from(y); self.dragging = true; actor.posn = actor::ActorPosn::FloatingPosn { x, @@ -186,8 +186,8 @@ impl EventHandler for Apr { ctx, &actor.image, drawparams.dest([ - board::START_X + board::BOARD_SQUARE_SIZE * (x as f32), - board::START_Y + board::BOARD_SQUARE_SIZE * (y as f32), + board::START_X + board::BOARD_SQUARE_SIZE * f32::from(x), + board::START_Y + board::BOARD_SQUARE_SIZE * f32::from(y), ]), )?, } diff --git a/src/board.rs b/src/board.rs index 03a9873..a444c0a 100644 --- a/src/board.rs +++ b/src/board.rs @@ -27,11 +27,11 @@ impl Board { //First, normalise to within the grid. let mut x = x; x = x.max(START_X); - x = x.min(START_X + (BOARD_SQUARE_SIZE * self.col as f32) - 1.0); + x = x.min(START_X + (BOARD_SQUARE_SIZE * f32::from(self.col)) - 1.0); let mut y = y; y = y.max(START_Y); - y = y.min(START_Y + (BOARD_SQUARE_SIZE * self.row as f32) - 1.0); + y = y.min(START_Y + (BOARD_SQUARE_SIZE * f32::from(self.row)) - 1.0); //Then, remove the start x and y x -= START_X; diff --git a/src/main.rs b/src/main.rs index c3f80d6..18e6b7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::cast_lossless +)] + use ggez::event; use ggez::{ContextBuilder, GameResult}; From 84bdbcbdfd2ab53a4147b495dee4e3169a5f1397 Mon Sep 17 00:00:00 2001 From: e-dt Date: Sat, 1 Jan 2022 20:57:07 +1100 Subject: [PATCH 2/2] Fmt --- src/main.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 18e6b7c..b24ee91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,4 @@ -#![warn( - clippy::cast_lossless -)] +#![warn(clippy::cast_lossless)] use ggez::event; use ggez::{ContextBuilder, GameResult};