Skip to content

Commit cac0e50

Browse files
committed
Add manhattan_distance_from function
1 parent ae56454 commit cac0e50

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

crates/utils/src/point.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! 2D & 3D point implementations.
22
3-
use crate::number::{Number, Signed, SignedInteger, UnsignedInteger};
3+
use crate::number::{Integer, Number, Signed, UnsignedInteger};
44
use std::fmt::Debug;
55
use std::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign};
66

@@ -25,11 +25,21 @@ macro_rules! point_impl {
2525
#[must_use]
2626
pub fn manhattan_distance(self) -> T::Unsigned
2727
where
28-
T: SignedInteger
28+
T: Integer
2929
{
3030
T::Unsigned::ZERO $(+ self.$f.unsigned_abs())+
3131
}
3232

33+
/// Returns the manhattan distance from the specified point.
34+
#[inline]
35+
#[must_use]
36+
pub fn manhattan_distance_from(self, rhs: Self) -> T::Unsigned
37+
where
38+
T: Integer
39+
{
40+
T::Unsigned::ZERO $(+ self.$f.abs_diff(rhs.$f))+
41+
}
42+
3343
/// Add the provided signed point, wrapping on overflow.
3444
///
3545
/// Useful for adding a signed direction onto an unsigned position.

0 commit comments

Comments
 (0)