use nalgebra::{Point2, Vector2};
use super::{CellTopology, Coord, GridTransform, Lattice, LatticeKind};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Hex;
impl Hex {
pub const fn new() -> Self {
Self
}
}
impl Lattice for Hex {
const KIND: LatticeKind = LatticeKind::Hex;
fn model_point(self, coord: Coord) -> Point2<f32> {
let q = coord.u as f32;
let r = coord.v as f32;
let half = 0.5_f32;
let sqrt3_over_2 = 3.0_f32.sqrt() * half;
Point2::new(q + half * r, sqrt3_over_2 * r)
}
fn neighbour_offsets(self) -> &'static [Coord] {
&HEX_AXIAL_OFFSETS
}
fn symmetry_transforms(self) -> &'static [GridTransform] {
&D6_TRANSFORMS
}
fn axis_family_count(self) -> usize {
3
}
fn model_axis_directions(self) -> &'static [Vector2<f32>] {
&HEX_AXIS_DIRECTIONS
}
fn cell_topology(self) -> CellTopology {
CellTopology::TriangleIsCell
}
}
static HEX_AXIS_DIRECTIONS: [Vector2<f32>; 3] = [
Vector2::new(1.0, 0.0),
Vector2::new(0.5, 0.866_025_4),
Vector2::new(-0.5, 0.866_025_4),
];
pub const HEX_AXIAL_OFFSETS: [Coord; 6] = [
Coord::new(1, 0),
Coord::new(1, -1),
Coord::new(0, -1),
Coord::new(-1, 0),
Coord::new(-1, 1),
Coord::new(0, 1),
];
pub const D6_TRANSFORMS: [GridTransform; 12] = [
GridTransform::new(LatticeKind::Hex, [[1, 0], [0, 1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[0, -1], [1, 1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[-1, -1], [1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[-1, 0], [0, -1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[0, 1], [-1, -1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[1, 1], [-1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[1, 1], [0, -1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[1, 0], [-1, -1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[0, -1], [-1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[-1, -1], [0, 1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[-1, 0], [1, 1]], [0, 0]),
GridTransform::new(LatticeKind::Hex, [[0, 1], [1, 0]], [0, 0]),
];