mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 00:01:34 +11:00
move some functions under more general generics
This commit is contained in:
parent
a6e4be0577
commit
4e0334f29c
|
@ -744,6 +744,17 @@ impl<T: Number + Signed> Vector2D<T> {
|
|||
y: self.y.abs(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Calculates the manhattan distance, x.abs() + y.abs().
|
||||
/// ```
|
||||
/// # use agb_fixnum::*;
|
||||
/// let v1: Vector2D<Num<i32, 8>> = (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<I: FixedWidthUnsignedInteger, const N: usize> Vector2D<Num<I, N>> {
|
||||
|
@ -790,28 +801,6 @@ impl<I: FixedWidthUnsignedInteger, const N: usize> Vector2D<Num<I, N>> {
|
|||
}
|
||||
|
||||
impl<const N: usize> Vector2D<Num<i32, N>> {
|
||||
#[must_use]
|
||||
/// Calculates the magnitude squared, ie (x*x + y*y)
|
||||
/// ```
|
||||
/// # use agb_fixnum::*;
|
||||
/// let v1: Vector2D<Num<i32, 8>> = (num!(3.), num!(4.)).into();
|
||||
/// assert_eq!(v1.magnitude_squared(), 25.into());
|
||||
/// ```
|
||||
pub fn magnitude_squared(self) -> Num<i32, N> {
|
||||
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<i32, 8>> = (num!(3.), num!(4.)).into();
|
||||
/// assert_eq!(v1.manhattan_distance(), 7.into());
|
||||
/// ```
|
||||
pub fn manhattan_distance(self) -> Num<i32, N> {
|
||||
self.x.abs() + self.y.abs()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Calculates the magnitude by square root
|
||||
/// ```
|
||||
|
@ -1168,6 +1157,17 @@ impl<T: Number> Vector2D<T> {
|
|||
y: self.x,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
/// Calculates the magnitude squared, ie (x*x + y*y)
|
||||
/// ```
|
||||
/// # use agb_fixnum::*;
|
||||
/// let v1: Vector2D<Num<i32, 8>> = (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<T: Number + Neg<Output = T>> Neg for Vector2D<T> {
|
||||
|
|
Loading…
Reference in a new issue