This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user