From: Tomas Wenström Date: Wed, 10 Feb 2021 19:40:07 +0000 (+0100) Subject: Fixed a bunch of clippy suggestions X-Git-Url: http://git.dolda2000.com/gitweb/?p=kaka%2Frust-sdl-test.git;a=commitdiff_plain;h=0c56b1f7a5568d6bfbebd196cf63ccef503cf959 Fixed a bunch of clippy suggestions --- diff --git a/src/common/geometry.rs b/src/common/geometry.rs index 50d1994..540db53 100644 --- a/src/common/geometry.rs +++ b/src/common/geometry.rs @@ -278,7 +278,7 @@ impl Intersection { let s = (-s1.y * (p1.x - p3.x) + s1.x * (p1.y - p3.y)) / denomimator; let t = ( s2.x * (p1.y - p3.y) - s2.y * (p1.x - p3.x)) / denomimator; - if s >= 0.0 && s <= 1.0 && t >= 0.0 && t <= 1.0 { + if (0.0..=1.0).contains(&s) && (0.0..=1.0).contains(&t) { return Intersection::Point(p1 + (s1 * t)) } } @@ -335,7 +335,7 @@ pub fn supercover_line_int(p1: Point, p2: Point) -> Vec 0 { 1 } else { -1 } ); - let mut p = p1.clone(); + let mut p = p1; let mut points = vec!(point!(p.x as isize, p.y as isize)); let mut i = point!(0, 0); while i.x < n.x || i.y < n.y { diff --git a/src/common/time.rs b/src/common/time.rs index 0468d5d..0902d94 100644 --- a/src/common/time.rs +++ b/src/common/time.rs @@ -9,7 +9,7 @@ pub struct ScopeTimer { impl ScopeTimer { pub fn new(name: &'static str) -> Self { - ScopeTimer { start: Instant::now(), name: name } + ScopeTimer { start: Instant::now(), name } } } diff --git a/src/core/app.rs b/src/core/app.rs index d440eb3..8bed04c 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -171,7 +171,7 @@ impl App { // if let Some(s) = self.states.last_mut() { // s.pause(); // } - state.enter(&mut self.ctrl_man); + state.enter(&self.ctrl_man); self.states.push(state); } StateChange::Pop => { @@ -262,7 +262,7 @@ impl App { fn render(&mut self) { self.renderer.clear(); - self.states.last_mut().unwrap().render(&mut self.renderer, &mut self.sprites); + self.states.last_mut().unwrap().render(&mut self.renderer, &self.sprites); self.renderer.present(); } } diff --git a/src/core/level/lvlgen.rs b/src/core/level/lvlgen.rs index daf27e8..8cdf6df 100644 --- a/src/core/level/lvlgen.rs +++ b/src/core/level/lvlgen.rs @@ -118,7 +118,7 @@ impl LevelGenerator { println!(" {} iterations needed", count); } - fn neighbours(&self, grid: &Vec>, px: usize, py: usize, distance: usize) -> u8 { + fn neighbours(&self, grid: &[Vec], px: usize, py: usize, distance: usize) -> u8 { let mut count = 0; for x in (px - distance)..=(px + distance) { for y in (py - distance)..=(py + distance) { @@ -292,7 +292,7 @@ impl Region { } #[allow(dead_code)] - fn print_grid(&self, grid: &Vec>) { + fn print_grid(&self, grid: &[Vec]) { let w = grid.len(); let h = grid[0].len(); let mut g = vec!(vec!(false; w); h); @@ -325,7 +325,7 @@ impl Region { grid } - fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &Vec>) -> Point { + fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &[Vec]) -> Point { let (ox, oy, w, h) = rect; let is_outer_wall = (ox, oy) == (&0, &0); // we know this is always the outer wall of the level for x in 0..*w { @@ -341,7 +341,7 @@ impl Region { panic!("no wall found!"); } - fn find_next_point_of_outline(&self, grid: &Vec>, p: &mut Point, directions: &mut Vec<(isize, isize)>) { + fn find_next_point_of_outline(&self, grid: &[Vec], p: &mut Point, directions: &mut Vec<(isize, isize)>) { directions.rotate_left(2); loop { let d = directions[0]; @@ -353,7 +353,7 @@ impl Region { } } - fn check(&self, p: Point, grid: &Vec>) -> bool { + fn check(&self, p: Point, grid: &[Vec]) -> bool { if p.x < 0 || p.x >= grid.len() as isize || p.y < 0 || p.y >= grid[0].len() as isize { false } else { diff --git a/src/teststate.rs b/src/teststate.rs index 5ea97bb..3437164 100644 --- a/src/teststate.rs +++ b/src/teststate.rs @@ -115,10 +115,9 @@ impl AppState for TestState { fn leave(&mut self) { } - fn handle_event(&mut self, _event: Event) -> Option { - match _event { - Event::MouseMotion { x, y, .. } => self.mouse = point!(x, y), - _ => {} + fn handle_event(&mut self, event: Event) -> Option { + if let Event::MouseMotion { x, y, .. } = event { + self.mouse = point!(x, y); } None }