1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::direction::angles::DIRECTION_ANGLE_OFFSET;
use crate::Direction;
const SQRT_3: f32 = 1.732_050_8;
static POINTY_ORIENTATION: HexOrientation = HexOrientation {
forward_matrix: [SQRT_3, SQRT_3 / 2.0, 0.0, 3.0 / 2.0],
inverse_matrix: [SQRT_3 / 3.0, -1.0 / 3.0, 0.0, 2.0 / 3.0],
angle_offset: DIRECTION_ANGLE_OFFSET, };
static FLAT_ORIENTATION: HexOrientation = HexOrientation {
forward_matrix: [3.0 / 2.0, 0.0, SQRT_3 / 2.0, SQRT_3],
inverse_matrix: [2.0 / 3.0, 0.0, -1.0 / 3.0, SQRT_3 / 3.0],
angle_offset: 0.0, };
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "ser_de", derive(serde::Serialize, serde::Deserialize))]
pub struct HexOrientation {
pub(crate) forward_matrix: [f32; 4],
pub(crate) inverse_matrix: [f32; 4],
pub(crate) angle_offset: f32,
}
impl HexOrientation {
#[inline]
#[must_use]
pub fn pointy() -> Self {
POINTY_ORIENTATION
}
#[inline]
#[must_use]
pub fn flat() -> Self {
FLAT_ORIENTATION
}
#[must_use]
#[inline]
pub fn direction_angle(&self, direction: Direction) -> f32 {
direction.angle(self)
}
}
impl Default for HexOrientation {
fn default() -> Self {
Self::flat()
}
}