Skip to content

Commit

Permalink
Add manhattan_distance_from function
Browse files Browse the repository at this point in the history
  • Loading branch information
ictrobot committed Dec 22, 2024
1 parent ae56454 commit cac0e50
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/utils/src/point.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! 2D & 3D point implementations.
use crate::number::{Number, Signed, SignedInteger, UnsignedInteger};
use crate::number::{Integer, Number, Signed, UnsignedInteger};
use std::fmt::Debug;
use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};

Expand All @@ -25,11 +25,21 @@ macro_rules! point_impl {
#[must_use]
pub fn manhattan_distance(self) -> T::Unsigned
where
T: SignedInteger
T: Integer
{
T::Unsigned::ZERO $(+ self.$f.unsigned_abs())+
}

/// Returns the manhattan distance from the specified point.
#[inline]
#[must_use]
pub fn manhattan_distance_from(self, rhs: Self) -> T::Unsigned
where
T: Integer
{
T::Unsigned::ZERO $(+ self.$f.abs_diff(rhs.$f))+
}

/// Add the provided signed point, wrapping on overflow.
///
/// Useful for adding a signed direction onto an unsigned position.
Expand Down

0 comments on commit cac0e50

Please sign in to comment.