48#include <gtest/gtest.h>
77 return static_cast<long long>(
_getpid());
79 return static_cast<long long>(
getpid());
92 static std::atomic<unsigned long long>
counter{0};
93 const auto tick = std::chrono::steady_clock::now().time_since_epoch().count();
94 return std::filesystem::temp_directory_path()
95 / (name +
"_" + std::to_string(
static_cast<long long>(
tick)) +
96 "_" + std::to_string(process_id()) +
97 "_" + std::to_string(
counter++));
100 std::string
read_file(
const std::filesystem::path &path,
bool binary =
false)
102 std::ifstream
in(path,
binary ? std::ios::binary :
std::ios::
in);
103 std::ostringstream
out;
114 opts.include_legend =
true;
115 opts.grid_colour =
"blue!20";
119 [](
int v) {
return v == 0 ? std::string(
"green!10") : std::string(
"red!80"); },
122 EXPECT_NE(
tikz.find(
"% Aleph::CA::render_rect_lattice_tikz"), std::string::npos);
123 EXPECT_NE(
tikz.find(
"\\begin{tikzpicture}"), std::string::npos);
124 EXPECT_NE(
tikz.find(
"fill=green!10, draw=blue!20"), std::string::npos);
125 EXPECT_NE(
tikz.find(
"fill=red!80, draw=blue!20"), std::string::npos);
126 EXPECT_NE(
tikz.find(
"rectangle (1, 0.5)"), std::string::npos);
143 hex.set_axial({1, 0}, 1);
146 EXPECT_NE(
hex_tikz.find(
"% Aleph::CA::render_hex_lattice_tikz"), std::string::npos);
151 tri.set_tri({1, 1}, 1);
154 EXPECT_NE(
tri_tikz.find(
"% Aleph::CA::render_triangular_lattice_tikz"), std::string::npos);
162 std::filesystem::remove_all(dir);
167 opts.format = Frame_Output_Format::PGM;
179 const auto p0 = dir /
"gol_000.pgm";
180 const auto p2 = dir /
"gol_002.pgm";
182 EXPECT_FALSE(std::filesystem::exists(dir /
"gol_001.pgm"));
191 std::filesystem::remove_all(dir);
197 std::filesystem::remove_all(dir);
204 const char *filename;
209 {Frame_Output_Format::RLE,
"rle",
"rle_000001.rle",
"x = 3, y = 2"},
210 {Frame_Output_Format::CSV,
"csv",
"csv_000001.csv",
"0,1,0"},
211 {Frame_Output_Format::JSON,
"json",
"json_000001.json",
"\"cells\":[[0,1,0],[0,0,1]]"},
212 {Frame_Output_Format::TikZ,
"tikz",
"tikz_000001.tex",
"\\begin{tikzpicture}"}
225 const auto path = dir /
tc.filename;
226 ASSERT_TRUE(std::filesystem::exists(path)) << path;
230 std::filesystem::remove_all(dir);
243 opts.prefix =
"frame";
244 opts.format = Frame_Output_Format::PPM;
248 EXPECT_NE(
cmd.find(
"ffmpeg -y -framerate 12"), std::string::npos);
249 EXPECT_NE(
cmd.find(
"frame_%04d.ppm"), std::string::npos);
252 std::filesystem::remove_all(dir);
size_t size_t int32_t * out
Directory-backed frame sinks for CA trajectories.
TikZ renderers for cellular-automata frames.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Directory-backed sink for CA frames.
std::string montage_command_hint(const std::string &output_file="ca.mp4", unsigned fps=24) const
Return an ffmpeg command hint for the current frame sequence.
void accept(std::size_t step, const Lattice &frame)
Accept a frame and write it if it passes the stride filter.
const Array< std::pair< std::size_t, std::filesystem::path > > & written_frames() const noexcept
Return the frame files written so far.
void flush() const
Write the optional manifest.
Hexagonal lattice with axial accessors over a 2D storage.
Lattice that adds boundary-aware access on top of a storage.
Triangular lattice with parity helpers over a 2D storage.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Frame_Output_Format
File format used by Directory_Frame_Sink.
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_lattice_tikz(std::ostream &out, const Lattice &frame, Palette &&palette, const Rect_Tikz_Options &opts={})
Render any supported 2D CA lattice as TikZ.
static void prefix(Node *root, DynList< Node * > &acc)
Itor find(const Itor &beg, const Itor &end, const T &value)
Find the first element equal to a value.
Default binary TikZ palette.
Options for directory-backed frame streams.
std::filesystem::path directory
destination directory
Out-of-range neighbours behave as if the lattice ended.
TikZ rendering options for rectangular frames.
double cell_size
cell side length in centimetres
Hexagonal lattice with axial / offset / cube coordinate conversions and a TikZ-compatible pixel mappi...
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).
Triangular lattice with up/down parity helpers and pixel mapping suitable for visualisation.