add "distance_to" fonction

This commit is contained in:
CoCo_Sol 2024-02-14 01:12:27 +01:00
parent 99489a46a1
commit 1fc89b08da

View file

@ -35,8 +35,10 @@ pub struct HexPosition {
impl HexPosition { impl HexPosition {
/// Returns the distance between two "HexPosition" /// Returns the distance between two "HexPosition"
pub fn distance_to(&self, other: &HexPosition) -> f32 { pub fn distance_to(&self, other: &HexPosition) -> f32 {
((self.q - other.q).abs()
1. + (self.r - other.r).abs()
+ (self.q + self.r - other.q - other.r).abs()) as f32
/ 2.
} }
/// Returns all positions in a given range /// Returns all positions in a given range