projective_grid/lattice/
square.rs1use nalgebra::{Point2, Vector2};
9
10use super::{CellTopology, Coord, GridTransform, Lattice, LatticeKind};
11
12#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
14#[non_exhaustive]
15pub struct Square;
16
17impl Square {
18 pub const fn new() -> Self {
20 Self
21 }
22}
23
24impl Lattice for Square {
25 const KIND: LatticeKind = LatticeKind::Square;
26
27 fn model_point(self, coord: Coord) -> Point2<f32> {
28 Point2::new(coord.u as f32, coord.v as f32)
29 }
30
31 fn neighbour_offsets(self) -> &'static [Coord] {
32 &SQUARE_CARDINAL_OFFSETS
33 }
34
35 fn symmetry_transforms(self) -> &'static [GridTransform] {
36 &D4_TRANSFORMS
37 }
38
39 fn axis_family_count(self) -> usize {
40 2
41 }
42
43 fn model_axis_directions(self) -> &'static [Vector2<f32>] {
44 &SQUARE_AXIS_DIRECTIONS
45 }
46
47 fn cell_topology(self) -> CellTopology {
48 CellTopology::TrianglePairToQuad
49 }
50}
51
52static SQUARE_AXIS_DIRECTIONS: [Vector2<f32>; 2] = [Vector2::new(1.0, 0.0), Vector2::new(0.0, 1.0)];
54
55pub const SQUARE_CARDINAL_OFFSETS: [Coord; 4] = [
57 Coord::new(1, 0),
58 Coord::new(0, 1),
59 Coord::new(-1, 0),
60 Coord::new(0, -1),
61];
62
63pub const D4_TRANSFORMS: [GridTransform; 8] = [
65 GridTransform::new(LatticeKind::Square, [[1, 0], [0, 1]], [0, 0]),
66 GridTransform::new(LatticeKind::Square, [[0, -1], [1, 0]], [0, 0]),
67 GridTransform::new(LatticeKind::Square, [[-1, 0], [0, -1]], [0, 0]),
68 GridTransform::new(LatticeKind::Square, [[0, 1], [-1, 0]], [0, 0]),
69 GridTransform::new(LatticeKind::Square, [[-1, 0], [0, 1]], [0, 0]),
70 GridTransform::new(LatticeKind::Square, [[1, 0], [0, -1]], [0, 0]),
71 GridTransform::new(LatticeKind::Square, [[0, 1], [1, 0]], [0, 0]),
72 GridTransform::new(LatticeKind::Square, [[0, -1], [-1, 0]], [0, 0]),
73];