From 4e0334f29cbe72ad39863b1f0b7e51ed2746a9c7 Mon Sep 17 00:00:00 2001 From: Corwin Date: Thu, 13 Jun 2024 22:47:03 +0100 Subject: [PATCH] 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 {