56#ifndef TPL_CA_TRIANGULAR_LATTICE_H
57#define TPL_CA_TRIANGULAR_LATTICE_H
91 return a.i == b.i
and a.j == b.j;
99 using unsigned_t = std::make_unsigned_t<ca_index_t>;
128 const double side)
noexcept
130 constexpr double sqrt3 = 1.7320508075688772;
131 const double height =
side *
sqrt3 / 2.0;
132 const double x = (
static_cast<double>(c.j) + 1.0) * (
side / 2.0);
133 const double y_base =
static_cast<double>(c.i) * height + height / 2.0;
149template <
typename Storage,
typename Boundary = OpenBoundary>
152 static_assert(Storage::rank == 2,
"Triangular_Lattice requires a 2D storage");
161 using base_type::base_type;
201template <
typename Lattice,
typename Palette>
205 const double side = 1.0)
207 os <<
"% Aleph::CA::render_triangular_lattice_tikz\n";
208 os <<
"\\begin{tikzpicture}[x=1cm, y=-1cm]\n";
216 os <<
" \\node[regular polygon, regular polygon sides=3, draw, fill=" <<
colour
217 <<
", inner sep=0pt, minimum size=" <<
side
218 <<
"cm, rotate=" <<
rotation <<
"] at (" <<
px[0] <<
", " <<
px[1] <<
") {};\n";
220 os <<
"\\end{tikzpicture}\n";
226template <
typename Lattice,
typename Palette>
231 std::ostringstream
oss;
Exception handling system with formatted messages for Aleph-w.
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
state_type at_safe(coord_type c) const
Boundary-aware read.
void set(const coord_type &c, const state_type &v)
Strict write: throws if c is out of range.
typename Storage::state_type state_type
typename Storage::extents_type extents_type
typename Storage::coord_type coord_type
static constexpr std::size_t rank
ca_size_t size() const noexcept
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
Triangular lattice with parity helpers over a 2D storage.
void set_tri(Tri_Coord c, const state_type &v)
Write cell value at triangular coords (i, j) (strict).
typename base_type::state_type state_type
typename base_type::extents_type extents_type
typename base_type::coord_type coord_type
state_type at_tri_safe(Tri_Coord c) const
Boundary-aware read at triangular coords.
state_type at_tri(Tri_Coord c) const
ca_size_t cols() const noexcept
Number of columns (axis 1).
static constexpr std::size_t rank
ca_size_t rows() const noexcept
< inherit constructors
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
constexpr int tri_parity(const Tri_Coord &c) noexcept
std::array< double, 2 > tri_pixel_centre(const Tri_Coord &c, const double side) noexcept
Cartesian centre of a triangle in (i, j) units.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
constexpr bool tri_is_down(const Tri_Coord &c) noexcept
constexpr bool tri_is_up(const Tri_Coord &c) noexcept
std::size_t ca_size_t
Unsigned size component used for extents and counts.
void render_triangular_lattice_tikz(std::ostream &os, const Lattice &lat, Palette &&palette, const double side=1.0)
Render a triangular frame as a TikZ picture.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Coordinates of a triangular cell as (i, j) integers.
friend constexpr bool operator!=(const Tri_Coord &a, const Tri_Coord &b) noexcept
friend constexpr bool operator==(const Tri_Coord &a, const Tri_Coord &b) noexcept
C++20 concepts for the Cellular Automata module.
Cellular automata lattice with pluggable boundary policies.