update calcule

This commit is contained in:
CoCo_Sol 2024-02-14 17:30:14 +01:00
parent fafdcc0b0b
commit 648bbf9c61

View file

@ -47,12 +47,12 @@ impl<T: HexNumber> HexPosition<T> {
/// ``` /// ```
pub fn distance_to(&self, other: &Self) -> T { pub fn distance_to(&self, other: &Self) -> T {
// Calculate the difference between the q and r coordinates. // Calculate the difference between the q and r coordinates.
let dq = self.q - other.q; let dq = (self.q - other.q).abs();
let dr = self.r - other.r; let dr = (self.r - other.r).abs();
let dz = self.q + self.r - other.q - other.r; let ds = dq + dr;
// Manhattan distance = (abs(dq) + abs(dr) + abs(ds)) / 2 // Manhattan distance = (abs(dq) + abs(dr) + abs(ds)) / 2
(dq.abs() + dr.abs() + dz.abs()) / (T::one() + T::one()) (dq + dr + ds) / (T::one() + T::one())
} }
} }