use nalgebra::{Point2, Vector2};
use super::{CellTopology, Coord, GridTransform, Lattice, LatticeKind};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Square;
impl Square {
pub const fn new() -> Self {
Self
}
}
impl Lattice for Square {
const KIND: LatticeKind = LatticeKind::Square;
fn model_point(self, coord: Coord) -> Point2<f32> {
Point2::new(coord.u as f32, coord.v as f32)
}
fn neighbour_offsets(self) -> &'static [Coord] {
&SQUARE_CARDINAL_OFFSETS
}
fn symmetry_transforms(self) -> &'static [GridTransform] {
&D4_TRANSFORMS
}
fn axis_family_count(self) -> usize {
2
}
fn model_axis_directions(self) -> &'static [Vector2<f32>] {
&SQUARE_AXIS_DIRECTIONS
}
fn cell_topology(self) -> CellTopology {
CellTopology::TrianglePairToQuad
}
}
static SQUARE_AXIS_DIRECTIONS: [Vector2<f32>; 2] = [Vector2::new(1.0, 0.0), Vector2::new(0.0, 1.0)];
pub const SQUARE_CARDINAL_OFFSETS: [Coord; 4] = [
Coord::new(1, 0),
Coord::new(0, 1),
Coord::new(-1, 0),
Coord::new(0, -1),
];
pub const D4_TRANSFORMS: [GridTransform; 8] = [
GridTransform::new(LatticeKind::Square, [[1, 0], [0, 1]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[0, -1], [1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[-1, 0], [0, -1]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[0, 1], [-1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[-1, 0], [0, 1]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[1, 0], [0, -1]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[0, 1], [1, 0]], [0, 0]),
GridTransform::new(LatticeKind::Square, [[0, -1], [-1, 0]], [0, 0]),
];