From 4da153b626e89bf9bfc00a253a1b93e5c5512910 Mon Sep 17 00:00:00 2001 From: CoCoSol007 Date: Wed, 14 Feb 2024 10:51:25 +0100 Subject: [PATCH] Fix clippy --- crates/border-wars/src/hex.rs | 44 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index 6ce4920..8026dc1 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -34,7 +34,7 @@ impl HexPosition { /// /// assert_eq!(a.distance_to(&b), 2.0); /// ``` - pub fn distance_to(&self, other: &HexPosition) -> f32 { + pub fn distance_to(&self, other: &Self) -> f32 { // dx = |x1 - x2| and x = q let dq = self.q - other.q; @@ -61,7 +61,7 @@ impl HexPosition { /// # Example: /// /// ```no_run - /// use border_wars::hex::HexPosition; + /// use border_wars::hex::Self; /// /// let position = HexPosition { q: 0, r: 0 }; /// @@ -69,56 +69,56 @@ impl HexPosition { /// /// assert_eq!(positions.len(), 7); /// ``` - pub fn range(&self, range: i32) -> HashSet { + pub fn range(&self, range: i32) -> HashSet { let mut result_positions = HashSet::new(); for q in (-range)..=range { for r in (-range).max(-q - range)..=range.min(-q + range) { - result_positions.insert(HexPosition { q, r }); + result_positions.insert(Self { q, r }); } } result_positions } } -impl ops::Add for HexPosition { - type Output = HexPosition; +impl ops::Add for HexPosition { + type Output = Self; - fn add(self, other: HexPosition) -> HexPosition { - HexPosition { + fn add(self, other: Self) -> Self::Output { + Self { q: self.q + other.q, r: self.r + other.r, } } } -impl ops::AddAssign for HexPosition { - fn add_assign(&mut self, other: HexPosition) { +impl ops::AddAssign for HexPosition { + fn add_assign(&mut self, other: Self) { *self = *self + other; } } -impl ops::Sub for HexPosition { - type Output = HexPosition; +impl ops::Sub for HexPosition { + type Output = Self; - fn sub(self, other: HexPosition) -> HexPosition { - HexPosition { + fn sub(self, other: Self) -> Self { + Self { q: self.q - other.q, r: self.r - other.r, } } } -impl ops::SubAssign for HexPosition { - fn sub_assign(&mut self, other: HexPosition) { +impl ops::SubAssign for HexPosition { + fn sub_assign(&mut self, other: Self) { *self = *self - other; } } impl ops::Mul for HexPosition { - type Output = HexPosition; + type Output = Self; - fn mul(self, other: i32) -> HexPosition { - HexPosition { + fn mul(self, other: i32) -> Self { + Self { q: self.q * other, r: self.r * other, } @@ -132,10 +132,10 @@ impl ops::MulAssign for HexPosition { } impl ops::Div for HexPosition { - type Output = HexPosition; + type Output = Self; - fn div(self, other: i32) -> HexPosition { - HexPosition { + fn div(self, other: i32) -> Self { + Self { q: self.q / other, r: self.r / other, }