hex coords unit tests wip
Some checks failed
Rust / build (push) Failing after 4s

This commit is contained in:
2026-03-14 20:56:06 -04:00
parent 13a74f7620
commit 227b654e50
9 changed files with 18 additions and 14 deletions

View File

@@ -103,7 +103,7 @@ impl HexCoord
};
}
pub fn from_grid_pos(x: usize, z: usize) -> Self
pub fn from_offset_pos(x: usize, z: usize) -> Self
{
return HexCoord::new(x as i32 - (z as i32 / 2), z as i32);
}
@@ -250,9 +250,9 @@ impl HexCoord
return (hex * -1).zxy();
}
pub fn scale(&self, dir: i32, radius: usize) -> HexCoord
pub fn scale(&self, dir: usize, radius: usize) -> HexCoord
{
let s = Self::DIRECTIONS[(dir % 6) as usize] * radius as i32;
let s = Self::DIRECTIONS[dir % 6] * radius as i32;
return Self::from_axial(self.hex.xy() + s.xy());
}

View File

@@ -3,5 +3,9 @@ use super::prelude::*;
#[test]
fn create_coord()
{
let coord = HexCoord::from_grid_pos(3, 3);
let center = HexCoord::from_offset_pos(3, 3);
for dir in 0..6
{
assert_eq!(center.get_neighbor(dir).get_neighbor(dir), center.scale(dir, 2));
}
}