diff --git a/crates/border-wars/src/hex.rs b/crates/border-wars/src/hex.rs index 492afd9..c775ded 100644 --- a/crates/border-wars/src/hex.rs +++ b/crates/border-wars/src/hex.rs @@ -16,10 +16,10 @@ impl HexNumber for T {} /// [documentation](https://www.redblobgames.com/grids/hexagons/#coordinates). #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct HexPosition { - /// Q coordinate + /// Q coordinate. pub q: T, - /// R coordinate + /// R coordinate. pub r: T, } @@ -46,13 +46,9 @@ impl HexPosition { /// assert_eq!(a.distance_to(&b), 2); /// ``` pub fn distance_to(&self, other: &Self) -> T { - // dx = |x1 - x2| where x = q + // Calculate the difference between the q and r coordinates. let dq = self.q - other.q; - - // dy = |y1 - y2| where y = r let dr = self.r - other.r; - - // dz = |z1 - z2| where z = -q - r let dz = self.q + self.r - other.q - other.r; // Manhattan distance = (abs(dq) + abs(dr) + abs(ds)) / 2