90template <
typename State>
107namespace ca_tikz_detail {
109template <
typename Lattice>
113 static_assert(
Lattice::rank == 2,
"Rectangular TikZ rendering requires rank 2");
138template <
typename Lattice,
typename Palette>
144 { p(v) } -> std::convertible_to<std::string>;
147 ca_tikz_detail::require_rank2_rect<Lattice>(
"render_rect_lattice_tikz");
150 <<
"render_rect_lattice_tikz: cell_size must be positive";
152 out <<
"% Aleph::CA::render_rect_lattice_tikz\n";
153 out <<
"\\begin{tikzpicture}[x=1cm, y=-1cm]\n";
157 const double x0 =
static_cast<double>(c) *
opts.cell_size;
158 const double y0 =
static_cast<double>(
r) *
opts.cell_size;
159 const double x1 =
x0 +
opts.cell_size;
160 const double y1 =
y0 +
opts.cell_size;
162 =
palette(frame.
at(
coord_t{static_cast<ca_index_t>(r), static_cast<ca_index_t>(c)}));
165 out <<
", draw=" <<
opts.grid_colour;
166 out <<
"] (" <<
x0 <<
", " <<
y0 <<
") rectangle (" << x1 <<
", " <<
y1 <<
");\n";
169 if (
opts.include_legend)
171 const double y = (
static_cast<double>(frame.
size(0)) + 0.7) *
opts.cell_size;
172 out <<
" \\path[fill=white, draw=" <<
opts.grid_colour <<
"] (0, " <<
y <<
") rectangle ("
173 <<
opts.cell_size <<
", " << (
y +
opts.cell_size) <<
");\n";
174 out <<
" \\node[anchor=west] at (" << (
opts.cell_size * 1.25) <<
", "
175 << (
y +
opts.cell_size * 0.5) <<
") {" <<
opts.dead_label <<
"};\n";
176 out <<
" \\path[fill=black, draw=" <<
opts.grid_colour <<
"] (" << (
opts.cell_size * 3.5)
177 <<
", " <<
y <<
") rectangle (" << (
opts.cell_size * 4.5) <<
", " << (
y +
opts.cell_size)
179 out <<
" \\node[anchor=west] at (" << (
opts.cell_size * 4.75) <<
", "
180 << (
y +
opts.cell_size * 0.5) <<
") {" <<
opts.alive_label <<
"};\n";
183 out <<
"\\end{tikzpicture}\n";
196template <
typename Lattice,
typename Palette>
201 { p(v) } -> std::convertible_to<std::string>;
204 std::ostringstream
out;
224template <
typename Lattice,
typename Palette>
230 { p(v) } -> std::convertible_to<std::string>;
250template <
typename Lattice,
typename Palette>
255 { p(v) } -> std::convertible_to<std::string>;
258 std::ostringstream
out;
273template <
typename Lattice>
288template <
typename Lattice>
292 std::ostringstream
out;
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
size_t size_t int32_t * out
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
typename Storage::state_type state_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.
Storage + topology that carries the cell values.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y0_function > > y0(const __gmp_expr< T, U > &expr)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void require_rank2_rect(const char *fn)
void render_rect_lattice_tikz(std::ostream &out, const Lattice &frame, Palette &&palette, const Rect_Tikz_Options &opts={})
Render a rectangular 2D frame as a TikZ picture.
void render_hex_lattice_tikz(std::ostream &os, const Lattice &lat, Palette &&palette, double radius=0.5, bool pointy_top=true)
Render a hex frame as a stand-alone TikZ picture.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
void render_lattice_tikz(std::ostream &out, const Lattice &frame, Palette &&palette, const Rect_Tikz_Options &opts={})
Render any supported 2D CA lattice as TikZ.
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.
Default binary TikZ palette.
std::string operator()(const State &v) const
Map a cell state to a TikZ fill colour.
std::string alive_colour
fill colour for live cells
std::string dead_colour
fill colour for dead cells
State dead
state considered dead
TikZ rendering options for rectangular frames.
std::string alive_label
legend label for live cells
double cell_size
cell side length in centimetres
bool draw_grid
draw cell borders
std::string grid_colour
TikZ colour used for grid lines.
bool include_legend
append a compact alive/dead legend
std::string dead_label
legend label for dead cells
C++20 concepts for the Cellular Automata module.
Hexagonal lattice with axial / offset / cube coordinate conversions and a TikZ-compatible pixel mappi...
Triangular lattice with up/down parity helpers and pixel mapping suitable for visualisation.