1use std::ops::Add;
2use crate::hex::Hex;
3
4pub struct HexDirection(usize);
5
6impl HexDirection {
7 pub const fn new(direction: i32) -> HexDirection {
8 let mod_direction: usize = (direction % 6) as usize;
9 HexDirection(mod_direction)
10 }
11
12 pub fn to_hex(&self) -> Hex {
13 HEX_DIRECTIONS[self.0]
14 }
15}
16
17impl Add for HexDirection {
18 type Output = HexDirection;
19
20 fn add(self, rhs: Self) -> Self::Output {
21 HexDirection(self.0 + rhs.0)
22 }
23}
24
25const HEX_DIRECTIONS: [Hex; 6] = [
26 Hex::new(0, -1, 1),
27 Hex::new(1, -1, 0),
28 Hex::new(1, 0, -1),
29 Hex::new(0, 1, -1),
30 Hex::new(-1, 1, 0),
31 Hex::new(-1, 0, 1),
32];