hexmap/
layout.rs

1#[derive(PartialOrd, PartialEq, Debug, Copy, Clone)]
2pub struct Orientation {
3    pub f0: f32,
4    pub f1: f32,
5    pub f2: f32,
6    pub f3: f32,
7    pub b0: f32,
8    pub b1: f32,
9    pub b2: f32,
10    pub b3: f32,
11    pub start_angle: f32,
12}
13
14impl Orientation {
15    const fn new(
16        f0: f32,
17        f1: f32,
18        f2: f32,
19        f3: f32,
20        b0: f32,
21        b1: f32,
22        b2: f32,
23        b3: f32,
24        start_angle: f32,
25    ) -> Orientation {
26        Orientation {
27            f0,
28            f1,
29            f2,
30            f3,
31            b0,
32            b1,
33            b2,
34            b3,
35            start_angle,
36        }
37    }
38}
39
40pub fn pointy() -> Orientation {
41    Orientation::new(
42        (3.0 as f32).sqrt(),
43        (3.0 as f32).sqrt() / 2.0,
44        0.0,
45        3.0 / 2.0,
46        (3.0 as f32).sqrt() / 3.0,
47        -1.0 / 3.0,
48        0.0,
49        2.0 / 3.0,
50        0.5,
51    )
52}
53
54pub fn flat() -> Orientation {
55    Orientation::new(
56        3.0 / 2.0,
57        0.0,
58        (3.0 as f32).sqrt() / 2.0,
59        (3.0 as f32).sqrt(),
60        2.0 / 3.0,
61        0.0,
62        -1.0 / 3.0,
63        (3.0 as f32).sqrt() / 3.0,
64        0.0,
65    )
66}
67
68#[derive(Debug, Copy, Clone)]
69pub struct Layout {
70    pub orientation: Orientation,
71    pub size: Point,
72    pub origin: Point,
73}
74
75impl Layout {
76    pub const fn new(orientation: Orientation, size: Point, origin: Point) -> Layout {
77        Layout {
78            orientation,
79            size,
80            origin,
81        }
82    }
83}
84
85#[derive(PartialOrd, PartialEq, Debug, Copy, Clone)]
86pub struct Point {
87    pub x: f32,
88    pub y: f32,
89}
90
91impl Point {
92    pub const fn new(x: f32, y: f32) -> Point {
93        Point { x, y }
94    }
95
96    pub const fn zero() -> Point {
97        Point::new(0.0, 0.0)
98    }
99}