From 0ccde7d328c5e34f9421a56595cd1e8c081c4a12 Mon Sep 17 00:00:00 2001 From: Corwin Kuiper Date: Sat, 7 Aug 2021 18:41:28 +0100 Subject: [PATCH] satisfy linter --- agb/src/display/tiled0.rs | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/agb/src/display/tiled0.rs b/agb/src/display/tiled0.rs index 1d9df4b8..7f4ed3b9 100644 --- a/agb/src/display/tiled0.rs +++ b/agb/src/display/tiled0.rs @@ -111,9 +111,7 @@ impl<'a> Map<'a> { } } fn get_position(&self, x: i32, y: i32) -> u16 { - if x < 0 || x as u32 >= self.dimensions.x { - self.default - } else if y < 0 || y as u32 >= self.dimensions.y { + if x < 0 || x as u32 >= self.dimensions.x || y < 0 || y as u32 >= self.dimensions.y { self.default } else { self.store[y as usize * self.dimensions.x as usize + x as usize] @@ -220,30 +218,22 @@ impl<'a> Background<'a> { let tile_position_difference = position_difference / 8; // how much of the map needs updating - let difference_x: Rect = if tile_position_difference.x == 0 { - Rect::new((0, 0).into(), (0, 0).into()) - } else if tile_position_difference.x > 0 { - Rect::new((0, 0).into(), (tile_position_difference.x, 0).into()) - } else if tile_position_difference.x < 0 { - Rect::new( + let difference_x: Rect = match tile_position_difference.x { + 0 => Rect::new((0, 0).into(), (0, 0).into()), + 1..=i32::MAX => Rect::new((0, 0).into(), (tile_position_difference.x, 0).into()), + i32::MIN..=-1 => Rect::new( (32 + tile_position_difference.x, 0).into(), (tile_position_difference.x.abs(), 0).into(), - ) - } else { - unreachable!(); + ), }; - let difference_y: Rect = if tile_position_difference.y == 0 { - Rect::new((0, 0).into(), (0, 0).into()) - } else if tile_position_difference.y > 0 { - Rect::new((0, 0).into(), (0, tile_position_difference.y).into()) - } else if tile_position_difference.y < 0 { - Rect::new( + let difference_y: Rect = match tile_position_difference.y { + 0 => Rect::new((0, 0).into(), (0, 0).into()), + 1..=i32::MAX => Rect::new((0, 0).into(), (0, tile_position_difference.y).into()), + i32::MIN..=-1 => Rect::new( (0, 32 + tile_position_difference.y).into(), (0, tile_position_difference.y.abs()).into(), - ) - } else { - unreachable!(); + ), }; // update those positions