From 4e0334f29cbe72ad39863b1f0b7e51ed2746a9c7 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 13 Jun 2024 22:47:03 +0100 Subject: [PATCH 1/2] move some functions under more general generics --- agb-fixnum/src/lib.rs | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/agb-fixnum/src/lib.rs b/agb-fixnum/src/lib.rs index d61852ae..499c0d21 100644 --- a/agb-fixnum/src/lib.rs +++ b/agb-fixnum/src/lib.rs @@ -744,6 +744,17 @@ impl Vector2D { y: self.y.abs(), } } + + #[must_use] + /// Calculates the manhattan distance, x.abs() + y.abs(). + /// ``` + /// # use agb_fixnum::*; + /// let v1: Vector2D> = (num!(3.), num!(4.)).into(); + /// assert_eq!(v1.manhattan_distance(), 7.into()); + /// ``` + pub fn manhattan_distance(self) -> T { + self.x.abs() + self.y.abs() + } } impl Vector2D> { @@ -790,28 +801,6 @@ impl Vector2D> { } impl Vector2D> { - #[must_use] - /// Calculates the magnitude squared, ie (x*x + y*y) - /// ``` - /// # use agb_fixnum::*; - /// let v1: Vector2D> = (num!(3.), num!(4.)).into(); - /// assert_eq!(v1.magnitude_squared(), 25.into()); - /// ``` - pub fn magnitude_squared(self) -> Num { - self.x * self.x + self.y * self.y - } - - #[must_use] - /// Calculates the manhattan distance, x.abs() + y.abs(). - /// ``` - /// # use agb_fixnum::*; - /// let v1: Vector2D> = (num!(3.), num!(4.)).into(); - /// assert_eq!(v1.manhattan_distance(), 7.into()); - /// ``` - pub fn manhattan_distance(self) -> Num { - self.x.abs() + self.y.abs() - } - #[must_use] /// Calculates the magnitude by square root /// ``` @@ -1168,6 +1157,17 @@ impl Vector2D { y: self.x, } } + + #[must_use] + /// Calculates the magnitude squared, ie (x*x + y*y) + /// ``` + /// # use agb_fixnum::*; + /// let v1: Vector2D> = (num!(3.), num!(4.)).into(); + /// assert_eq!(v1.magnitude_squared(), 25.into()); + /// ``` + pub fn magnitude_squared(self) -> T { + self.x * self.x + self.y * self.y + } } impl> Neg for Vector2D { From f6ff13e1b2a62894d2c2c5733026c70c8e326485 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 13 Jun 2024 22:49:39 +0100 Subject: [PATCH 2/2] add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b96ae87..24bcfc4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- `manhattan_distance` and `magnitude_squared` no longer require the fixed point number. + ## [0.20.3] - 2024/06/12 ### Added