1#include <gtest/gtest.h>
11#include <system_error>
23bool has_nan_or_inf(std::string s)
26 c = static_cast<char>(::
tolower(static_cast<unsigned char>(c)));
28 return s.find(
"nan") != std::string::npos or
29 s.find(
"inf") != std::string::npos;
32#ifdef ALEPH_PDFLATEX_EXECUTABLE
37 std::string quoted =
"'";
38 for (
const char c :
value)
47class Scoped_Latex_Temp_Directory
49 std::filesystem::path path_;
52 Scoped_Latex_Temp_Directory()
54 const auto stamp = std::chrono::high_resolution_clock::now()
55 .time_since_epoch().count();
56 path_ = std::filesystem::temp_directory_path() /
57 (
"aleph-tikz-latex-" + std::to_string(stamp));
58 std::filesystem::create_directories(path_);
61 Scoped_Latex_Temp_Directory(
const Scoped_Latex_Temp_Directory &) =
delete;
62 Scoped_Latex_Temp_Directory & operator=(
63 const Scoped_Latex_Temp_Directory &) =
delete;
65 ~Scoped_Latex_Temp_Directory()
67 std::error_code
error;
68 std::filesystem::remove_all(path_,
error);
72 [[nodiscard]]
const std::filesystem::path & path() const noexcept
79bool write_text_file(
const std::filesystem::path & path,
80 const std::string & text)
82 std::ofstream
output(path);
88std::string read_text_file(
const std::filesystem::path & path)
90 std::ifstream input(path);
91 return {std::istreambuf_iterator<char>(input),
92 std::istreambuf_iterator<char>()};
119Polygon make_shortest_path_polygon()
134Polygon make_concave_for_decomposition()
149Polygon make_convex_for_calipers()
161Polygon make_visibility_polygon()
179 for (
auto it = pts.
get_it(); it.has_curr(); it.next_ne())
191TEST(TikzGeomAlgorithmsTest, LayerOrderIsRespected)
201 std::ostringstream
output;
203 const std::string result =
output.str();
205 const size_t green_pos = result.find(
"draw=green");
206 const size_t red_pos = result.find(
"draw=red");
208 ASSERT_NE(green_pos, std::string::npos);
209 ASSERT_NE(red_pos, std::string::npos);
210 EXPECT_LT(green_pos, red_pos);
213TEST(TikzGeomAlgorithmsTest, VisualizeConvexHull)
227 plane, pts, hull_algo,
232 EXPECT_GE(hull.
size(), 3U);
234 std::ostringstream
output;
236 const std::string result =
output.str();
238 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
239 EXPECT_FALSE(has_nan_or_inf(result));
242TEST(TikzGeomAlgorithmsTest, VisualizeConvexIntersection)
244 const Polygon a = make_convex_a();
245 const Polygon b = make_convex_b();
250 EXPECT_GT(inter.
size(), 0U);
252 std::ostringstream
output;
254 const std::string result =
output.str();
256 EXPECT_NE(result.find(
"fill=red!30"), std::string::npos);
257 EXPECT_FALSE(has_nan_or_inf(result));
260TEST(TikzGeomAlgorithmsTest, VisualizeVoronoi)
272 EXPECT_EQ(vor.sites.size(), 5U);
274 std::ostringstream
output;
276 const std::string result =
output.str();
278 EXPECT_NE(result.find(
"dashed"), std::string::npos);
279 EXPECT_FALSE(has_nan_or_inf(result));
282TEST(TikzGeomAlgorithmsTest, VisualizeDelaunay)
296 EXPECT_GE(dt.sites.size(), 5U);
297 EXPECT_GT(dt.triangles.size(), 0U);
299 std::ostringstream
output;
301 const std::string result =
output.str();
302 EXPECT_NE(result.find(
"draw=blue"), std::string::npos);
303 EXPECT_FALSE(has_nan_or_inf(result));
306TEST(TikzGeomAlgorithmsTest, VisualizePowerDiagram)
317 EXPECT_EQ(pd.sites.size(), 4U);
319 std::ostringstream
output;
321 const std::string result =
output.str();
323 EXPECT_NE(result.find(
"violet"), std::string::npos);
324 EXPECT_FALSE(has_nan_or_inf(result));
327TEST(TikzGeomAlgorithmsTest, VisualizeSegmentArrangement)
343 EXPECT_GT(arrangement.vertices.size(), 4U);
344 EXPECT_GT(arrangement.edges.size(), 3U);
346 std::ostringstream
output;
348 const std::string result =
output.str();
350 EXPECT_NE(result.find(
"teal!70!black"), std::string::npos);
351 EXPECT_FALSE(has_nan_or_inf(result));
354TEST(TikzGeomAlgorithmsTest, VisualizeSegmentArrangementFaceColoring)
372 EXPECT_GT(arrangement.faces.size(), 1U);
374 std::ostringstream
output;
376 const std::string result =
output.str();
378 EXPECT_NE(result.find(
"blue!20"), std::string::npos);
379 EXPECT_FALSE(has_nan_or_inf(result));
382TEST(TikzGeomAlgorithmsTest, VisualizeShortestPathInPolygon)
384 const Polygon polygon = make_shortest_path_polygon();
385 const Point source(2, 16);
386 const Point target(18, 16);
392 EXPECT_GE(count_points(path), 2U);
394 std::ostringstream
output;
396 const std::string result =
output.str();
398 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
399 EXPECT_NE(result.find(
"fill=green!50!black"), std::string::npos);
400 EXPECT_NE(result.find(
"fill=blue"), std::string::npos);
401 EXPECT_FALSE(has_nan_or_inf(result));
404TEST(TikzGeomAlgorithmsTest, VisualizeAlphaShape)
420 EXPECT_GT(alpha_shape.boundary_edges.size(), 0U);
422 std::ostringstream
output;
424 const std::string result =
output.str();
426 EXPECT_NE(result.find(
"orange!90!black"), std::string::npos);
427 EXPECT_FALSE(has_nan_or_inf(result));
430TEST(TikzGeomAlgorithmsTest, VisualizeRegularTriangulation)
442 EXPECT_GE(rt.sites.size(), 4U);
443 EXPECT_GT(rt.triangles.size(), 0U);
445 std::ostringstream
output;
447 const std::string result =
output.str();
448 EXPECT_NE(result.find(
"blue!60"), std::string::npos);
449 EXPECT_FALSE(has_nan_or_inf(result));
452TEST(TikzGeomAlgorithmsTest, VisualizeClosestPair)
464 EXPECT_TRUE(cp.distance_squared >= 0);
466 std::ostringstream
output;
468 const std::string result =
output.str();
469 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
470 EXPECT_FALSE(has_nan_or_inf(result));
473TEST(TikzGeomAlgorithmsTest, VisualizeRotatingCalipers)
475 const Polygon poly = make_convex_for_calipers();
480 EXPECT_TRUE(rc.diameter.distance_squared > 0);
481 EXPECT_TRUE(rc.width.width_squared >= 0);
483 std::ostringstream
output;
485 const std::string result =
output.str();
486 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
487 EXPECT_NE(result.find(
"draw=blue"), std::string::npos);
488 EXPECT_FALSE(has_nan_or_inf(result));
491TEST(TikzGeomAlgorithmsTest, VisualizeHalfPlaneIntersection)
493 const Polygon clip = make_convex_for_calipers();
499 EXPECT_GT(inter.
size(), 0U);
501 std::ostringstream
output;
503 const std::string result =
output.str();
504 EXPECT_NE(result.find(
"fill=red!25"), std::string::npos);
505 EXPECT_FALSE(has_nan_or_inf(result));
508TEST(TikzGeomAlgorithmsTest, VisualizeMinkowskiSum)
525 EXPECT_GT(
sum.size(), 0U);
527 std::ostringstream
output;
529 const std::string result =
output.str();
530 EXPECT_NE(result.find(
"fill=red!26"), std::string::npos);
531 EXPECT_FALSE(has_nan_or_inf(result));
534TEST(TikzGeomAlgorithmsTest, VisualizeMonotoneTriangulation)
536 const Polygon concave = make_concave_for_decomposition();
540 size_t tri_count = 0;
541 for (
auto it = tris.
get_it(); it.has_curr(); it.next_ne())
543 EXPECT_GT(tri_count, 0U);
545 std::ostringstream
output;
547 const std::string result =
output.str();
548 EXPECT_NE(result.find(
"blue!65"), std::string::npos);
549 EXPECT_FALSE(has_nan_or_inf(result));
552TEST(TikzGeomAlgorithmsTest, VisualizeVisibilityPolygon)
554 const Polygon polygon = make_visibility_polygon();
555 const Point query(2, 16);
559 EXPECT_GT(vis.
size(), 0U);
561 std::ostringstream
output;
563 const std::string result =
output.str();
564 EXPECT_NE(result.find(
"orange!90!black"), std::string::npos);
565 EXPECT_FALSE(has_nan_or_inf(result));
568TEST(TikzGeomAlgorithmsTest, VisualizeLineSweep)
578 EXPECT_GT(intersections.size(), 0U);
580 std::ostringstream
output;
582 const std::string result =
output.str();
583 EXPECT_NE(result.find(
"blue!60"), std::string::npos);
584 EXPECT_NE(result.find(
"fill=red"), std::string::npos);
585 EXPECT_FALSE(has_nan_or_inf(result));
588TEST(TikzGeomAlgorithmsTest, VisualizeKDTreePartitions)
601 EXPECT_EQ(snap.points.size(), points.
size());
602 EXPECT_GT(snap.partitions.size(), 0U);
604 std::ostringstream
output;
606 const std::string result =
output.str();
607 EXPECT_NE(result.find(
"fill=red"), std::string::npos);
608 EXPECT_FALSE(has_nan_or_inf(result));
611TEST(TikzGeomAlgorithmsTest, VisualizeRangeTreeAndQuery)
627 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
628 EXPECT_GT(viz.query_hits.size(), 0U);
630 std::ostringstream
output;
632 const std::string result =
output.str();
633 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
634 EXPECT_FALSE(has_nan_or_inf(result));
637TEST(TikzGeomAlgorithmsTest, VisualizeAABBTreeAndQuery)
650 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
651 EXPECT_GT(viz.query_hit_ids.size(), 0U);
653 std::ostringstream
output;
655 const std::string result =
output.str();
656 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
657 EXPECT_FALSE(has_nan_or_inf(result));
660TEST(TikzGeomAlgorithmsTest, VisualizeRTreeAndQuery)
670 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
671 EXPECT_GT(viz.query_hit_boxes.size(), 0U);
673 std::ostringstream
output;
675 const std::string result =
output.str();
676 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
677 EXPECT_FALSE(has_nan_or_inf(result));
680TEST(TikzGeomAlgorithmsTest, VisualizeRStarTreeAndQuery)
690 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
691 EXPECT_GT(viz.query_hit_boxes.size(), 0U);
693 std::ostringstream
output;
695 const std::string result =
output.str();
696 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
697 EXPECT_FALSE(has_nan_or_inf(result));
700TEST(TikzGeomAlgorithmsTest, VisualizeRTreeWithoutQuery)
703 for (
int i = 0; i < 20; ++i)
708 EXPECT_GT(snapshot.
nodes.size(), 0U);
710 std::ostringstream
output;
712 EXPECT_FALSE(has_nan_or_inf(
output.str()));
715TEST(TikzGeomAlgorithmsTest, VisualizeShortestPathWithPortals)
717 const Polygon polygon = make_shortest_path_polygon();
718 const Point source(2, 16);
719 const Point target(18, 16);
725 EXPECT_GE(debug.portals.size(), 2U);
726 EXPECT_GE(count_points(debug.path), 2U);
728 std::ostringstream
output;
730 const std::string result =
output.str();
732 EXPECT_NE(result.find(
"draw=purple"), std::string::npos);
733 EXPECT_NE(result.find(
"dashed"), std::string::npos);
734 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
735 EXPECT_FALSE(has_nan_or_inf(result));
738TEST(TikzGeomAlgorithmsTest, VisualizeConvexDecomposition)
740 const Polygon concave = make_concave_for_decomposition();
748 EXPECT_GT(parts.size(), 1U);
750 std::ostringstream
output;
752 const std::string result =
output.str();
754 EXPECT_NE(result.find(
"blue!20"), std::string::npos);
755 EXPECT_FALSE(has_nan_or_inf(result));
758TEST(TikzGeomAlgorithmsTest, ComputeFunnelTrace)
760 const Polygon polygon = make_shortest_path_polygon();
761 const Point source(2, 16);
762 const Point target(18, 16);
767 EXPECT_GE(trace.portals.size(), 2U);
768 EXPECT_GT(trace.steps.size(), 0U);
769 EXPECT_GE(count_points(trace.final_path), 2U);
770 EXPECT_EQ(trace.final_path(0), source);
771 EXPECT_EQ(trace.final_path(trace.final_path.size() - 1), target);
774TEST(TikzGeomAlgorithmsTest, PutFunnelTraceStepRenders)
776 const Polygon polygon = make_shortest_path_polygon();
777 const Point source(2, 16);
778 const Point target(18, 16);
782 ASSERT_GT(trace.steps.size(), 0U);
787 std::ostringstream
output;
789 const std::string result =
output.str();
791 EXPECT_NE(result.find(
"draw=purple"), std::string::npos);
792 EXPECT_NE(result.find(
"draw=orange!90!black"), std::string::npos);
793 EXPECT_FALSE(has_nan_or_inf(result));
796TEST(TikzGeomSceneTest, ComposeMultipleAlgorithmsInSingleScene)
819 for (
size_t i = 0; i < arrangement.vertices.size(); ++i)
820 arrangement_points.
append(arrangement.vertices(i));
832 EXPECT_GE(hull.
size(), 3U);
834 const std::string tikz = scene.
to_tikz();
835 EXPECT_NE(tikz.find(
"draw=teal!70!black"), std::string::npos);
836 EXPECT_NE(tikz.find(
"draw=red"), std::string::npos);
837 EXPECT_FALSE(has_nan_or_inf(tikz));
840TEST(TikzGeomSceneTest, NewVisualizationWrappers)
852 EXPECT_GT(dt.triangles.size(), 0U);
855 EXPECT_TRUE(cp.distance_squared >= 0);
861 EXPECT_GT(intersections.size(), 0U);
870 EXPECT_GT(kd_snap.partitions.size(), 0U);
877 range_tree.
build(range_points);
880 EXPECT_GT(rv.query_hits.size(), 0U);
886 aabb_tree.
build(aabb_entries);
889 EXPECT_GT(av.query_hit_ids.size(), 0U);
891 const std::string tikz = scene.
to_tikz();
892 EXPECT_NE(tikz.find(
"draw=blue"), std::string::npos);
893 EXPECT_NE(tikz.find(
"draw=red"), std::string::npos);
894 EXPECT_FALSE(has_nan_or_inf(tikz));
897TEST(TikzGeomSceneTest, StandaloneExportWrapsTikzPicture)
906 EXPECT_NE(latex.find(
"\\documentclass[tikz,border=6pt]{standalone}"),
908 EXPECT_NE(latex.find(
"}\n\\usepackage{tikz}\n"), std::string::npos);
909 EXPECT_EQ(latex.find(
"}\\n\\usepackage{tikz}\\n"), std::string::npos);
910 EXPECT_NE(latex.find(
"\\usepackage{tikz}"), std::string::npos);
911 EXPECT_NE(latex.find(
"\\begin{tikzpicture}"), std::string::npos);
912 EXPECT_NE(latex.find(
"\\end{document}"), std::string::npos);
913 EXPECT_FALSE(has_nan_or_inf(latex));
916TEST(TikzGeomSceneTest, StandaloneAndOverlayExportsCollectPatternDependency)
920 pattern.
pattern =
"north east lines";
925 const size_t library_pos = standalone.find(
"\\usetikzlibrary{patterns}");
926 ASSERT_NE(library_pos, std::string::npos);
927 EXPECT_LT(library_pos, standalone.find(
"\\begin{document}"));
929 std::vector<Tikz_Scene>
steps;
930 steps.push_back(patterned);
931 steps.emplace_back(120, 80, 0, 0,
true);
935 const size_t overlay_library_pos =
936 overlays.find(
"\\usetikzlibrary{patterns}");
937 ASSERT_NE(overlay_library_pos, std::string::npos);
938 EXPECT_LT(overlay_library_pos, overlays.find(
"\\begin{document}"));
941TEST(TikzGeomSceneTest, PatternDependencyCanComeOnlyFromExplicitLegend)
945 pattern.
pattern =
"north east lines";
950 EXPECT_NE(standalone.find(
"\\usetikzlibrary{patterns}"),
952 EXPECT_NE(standalone.find(
"Patterned region"), std::string::npos);
955TEST(TikzGeomSceneTest, PatternDependencyCanComeOnlyFromRegisteredStyle)
964 EXPECT_NE(standalone.find(
"\\usetikzlibrary{patterns}"),
966 EXPECT_NE(standalone.find(
"\\tikzset{patternedArea/.style="),
970TEST(TikzGeomSceneTest, BeamerExportWrapsSingleFrame)
980 const std::string latex = scene.
to_beamer(opts);
982 EXPECT_NE(latex.find(
"\\documentclass[aspectratio=43]{beamer}"),
984 EXPECT_NE(latex.find(
"\\setbeamertemplate{navigation symbols}{}"),
986 EXPECT_NE(latex.find(
"\\begin{frame}[t]{Scene Demo}"), std::string::npos);
987 EXPECT_NE(latex.find(
"\\usepackage{graphicx}"), std::string::npos);
988 EXPECT_NE(latex.find(
"\\scalebox{"), std::string::npos);
989 EXPECT_NE(latex.find(
"\\begin{tikzpicture}"), std::string::npos);
990 EXPECT_EQ(latex.find(
"\\documentclass[handout,aspectratio=43]{beamer}"),
992 EXPECT_FALSE(has_nan_or_inf(latex));
995TEST(TikzGeomSceneTest, HandoutExportAddsHandoutClassOption)
1004 const std::string latex = scene.
to_handout(opts);
1006 EXPECT_NE(latex.find(
"\\documentclass[handout,aspectratio=169]{beamer}"),
1008 EXPECT_NE(latex.find(
"\\begin{frame}[t]{Handout Demo}"), std::string::npos);
1009 EXPECT_FALSE(has_nan_or_inf(latex));
1012 const std::string latex_no_dup = scene.
to_handout(opts);
1013 EXPECT_NE(latex_no_dup.find(
"\\documentclass[handout,aspectratio=169]{beamer}"),
1015 EXPECT_EQ(latex_no_dup.find(
"handout,handout"), std::string::npos);
1018TEST(TikzGeomSceneTest, BeamerOverlaysExportWrapsOnlyBlocks)
1020 std::vector<Tikz_Scene>
steps;
1021 steps.emplace_back(120, 80, 0, 0,
true);
1023 steps.emplace_back(120, 80, 0, 0,
true);
1033 EXPECT_NE(latex.find(
"\\documentclass[aspectratio=169]{beamer}"),
1035 EXPECT_NE(latex.find(
"\\begin{frame}[t]{Overlay Demo}"), std::string::npos);
1036 EXPECT_NE(latex.find(
"\\only<1>{"), std::string::npos);
1037 EXPECT_NE(latex.find(
"\\only<2>{"), std::string::npos);
1038 EXPECT_NE(latex.find(
"\\scalebox{"), std::string::npos);
1039 EXPECT_EQ(latex.find(
"\\only<3>{"), std::string::npos);
1040 EXPECT_EQ(latex.find(
"\\documentclass[handout,aspectratio=169]{beamer}"),
1042 EXPECT_FALSE(has_nan_or_inf(latex));
1045TEST(TikzGeomSceneTest, HandoutOverlaysAddsHandoutClassOption)
1047 std::vector<Tikz_Scene>
steps;
1048 steps.emplace_back(120, 80, 0, 0,
true);
1050 steps.emplace_back(120, 80, 0, 0,
true);
1059 EXPECT_NE(latex.find(
"\\documentclass[handout,aspectratio=43]{beamer}"),
1061 EXPECT_EQ(latex.find(
"handout,handout"), std::string::npos);
1062 EXPECT_EQ(latex.find(
"\\only<1>{"), std::string::npos);
1063 EXPECT_NE(latex.find(
"draw=blue"), std::string::npos);
1064 EXPECT_EQ(latex.find(
"fill=black"), std::string::npos);
1065 const size_t picture = latex.find(
"\\begin{tikzpicture}");
1066 ASSERT_NE(picture, std::string::npos);
1067 EXPECT_EQ(latex.find(
"\\begin{tikzpicture}", picture + 1),
1069 EXPECT_FALSE(has_nan_or_inf(latex));
1072TEST(TikzGeomSceneTest, BeamerRejectsInvalidPictureBounds)
1077 EXPECT_THROW(scene.
to_beamer(opts), std::domain_error);
1080TEST(TikzGeomSceneTest, BeamerOverlaysHandlesEmptySteps)
1082 const std::vector<Tikz_Scene>
steps;
1085 EXPECT_NE(latex.find(
"No overlays provided."), std::string::npos);
1086 EXPECT_EQ(latex.find(
"\\only<1>{"), std::string::npos);
1087 EXPECT_FALSE(has_nan_or_inf(latex));
1090TEST(TikzGeomSceneTest, GeneratedLatexDocumentsCompileWithoutLayoutOverflow)
1092#ifndef ALEPH_PDFLATEX_EXECUTABLE
1093 GTEST_SKIP() <<
"pdflatex, standalone, beamer, or TikZ is unavailable";
1097 pattern.
pattern =
"north east lines";
1101 std::vector<Tikz_Scene>
steps;
1102 for (
size_t i = 0; i < 3; ++i)
1104 steps.emplace_back(178, 108, 0, 0,
true);
1107 Point(20, 20 -
static_cast<long>(i))),
1116 Scoped_Latex_Temp_Directory temporary;
1117 const std::vector<std::pair<std::string, std::string>> documents = {
1120 {
"handout", handout}
1123 for (
const auto & [name, document] : documents)
1125 const std::filesystem::path tex = temporary.path() / (name +
".tex");
1126 const std::filesystem::path transcript =
1127 temporary.path() / (name +
".stdout");
1128 ASSERT_TRUE(write_text_file(tex, document));
1130 const std::string command =
1131 shell_quote(ALEPH_PDFLATEX_EXECUTABLE) +
1132 " -interaction=nonstopmode -halt-on-error -output-directory=" +
1133 shell_quote(temporary.path().string()) +
" " +
1134 shell_quote(tex.string()) +
" > " +
1135 shell_quote(transcript.string()) +
" 2>&1";
1136 const int status = std::system(command.c_str());
1137 const std::string diagnostics = read_text_file(transcript);
1138 ASSERT_EQ(status, 0) << name <<
" failed:\n" << diagnostics;
1140 const std::string
log =
1141 read_text_file(temporary.path() / (name +
".log"));
1142 EXPECT_EQ(
log.find(
"Overfull"), std::string::npos)
1143 << name <<
" contains a layout overflow:\n" <<
log;
1144 EXPECT_EQ(
log.find(
"LaTeX Error"), std::string::npos)
1145 << name <<
" contains a LaTeX error:\n" <<
log;
1146 EXPECT_EQ(
log.find(
"Undefined control sequence"), std::string::npos)
1147 << name <<
" contains an undefined command:\n" <<
log;
size_t size_t int32_t value
Axis-aligned bounding box tree for spatial queries.
size_t build(Array< size_t > &idx, const size_t lo, const size_t hi)
Alpha shape of a point set.
Andrew's monotonic chain convex hull algorithm.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
T & append(const T &data)
Append a copy of data
Decompose a simple polygon into convex parts using Hertel-Mehlhorn.
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
static Array< HalfPlane > from_convex_polygon(const Polygon &poly)
Build half-planes from the edges of a closed convex polygon.
static KDTreePointSearch build(const Array< Point > &points, const Geom_Number &xmin, const Geom_Number &ymin, const Geom_Number &xmax, const Geom_Number &ymax)
Build a balanced KD-tree from a point array.
Represents a point with rectangular coordinates in a 2D plane.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
void close()
Close the polygon.
const size_t & size() const
Get the number of vertices.
Dynamic R-tree indexing axis-aligned rectangles by payload.
void insert(const Rectangle &bbox, const Payload &value)
Insert a (bbox, value) entry, copying value.
Static 2D range tree for orthogonal range queries.
void build(const DynList< Point > &points)
Build the range tree from a point set.
An axis-aligned rectangle.
Compute the full planar subdivision induced by a set of segments.
Represents a line segment between two points.
Compute the shortest Euclidean path between two points inside a simple polygon.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
static constexpr int Layer_Default
static constexpr int Layer_Overlay
High-level scene wrapper to compose objects and algorithm visualizations.
auto visualize_closest_pair(Args &&... args)
std::string to_standalone(const Tikz_Standalone_Document_Options &options={}) const
static std::string to_handout_overlays(const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
String variant of draw_handout_overlays.
std::string to_tikz() const
auto visualize_segment_arrangement(Args &&... args)
auto visualize_line_sweep(Args &&... args)
Tikz_Scene & put_cartesian_axis()
Tikz_Scene & add_legend_entry(const std::string &label, const Tikz_Style &style)
auto visualize_range_tree_query(Args &&... args)
Tikz_Scene & add(const Geom &object)
std::string to_handout(const Tikz_Beamer_Document_Options &options={}) const
Tikz_Scene & register_tikz_style(const std::string &name, const Tikz_Style &style)
static std::string to_beamer_overlays(const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
String variant of draw_beamer_overlays.
auto visualize_aabb_tree_query(Args &&... args)
auto visualize_kdtree_partitions(Args &&... args)
Polygon visualize_convex_hull(const Points &points, HullAlgorithm &&algorithm, Args &&... args)
auto visualize_delaunay(Args &&... args)
Tikz_Scene & set_point_radius_mm(const double radius_mm)
std::string to_beamer(const Tikz_Beamer_Document_Options &options={}) const
A non-degenerate triangle defined by three points.
O(n log n) Voronoi diagram construction.
auto get_it()
Return a properly initialized iterator positioned at the first item on the container.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_log_function > > log(const __gmp_expr< T, U > &expr)
std::string shell_quote(const std::string &s)
Main namespace for Aleph-w library functions.
AABBTreeQueryVizResult visualize_aabb_tree_query(Tikz_Plane &plane, const AABBTree &tree, const Rectangle &query_rect, const Tikz_Style &node_bbox_style=tikz_wire_style("teal!70!black"), const Tikz_Style &leaf_bbox_style=tikz_wire_style("blue!70"), const Tikz_Style &query_rect_style=tikz_wire_style("red", true), const Tikz_Style &query_hit_style=tikz_wire_style("red"))
Visualize AABB tree with a rectangle query overlay.
std::string tolower(const char *str)
Convert a C std::string to lower-case.
Polygon visualize_convex_intersection(Tikz_Plane &plane, const Polygon &subject, const Polygon &clip, const ConvexPolygonIntersectionBasic &intersection_algorithm={}, const Tikz_Style &subject_style=tikz_area_style("blue", "blue!15", 0.45), const Tikz_Style &clip_style=tikz_area_style("orange", "orange!20", 0.45), const Tikz_Style &result_style=tikz_area_style("red", "red!30", 0.60), const int input_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Visualizes the intersection of two convex polygons.
AlphaShape::Result visualize_alpha_shape(Tikz_Plane &plane, const DynList< Point > &points, const Geom_Number &alpha_squared, const AlphaShape &algorithm={}, const bool draw_kept_triangles=false, const Tikz_Style &triangle_style=tikz_wire_style("gray!55"), const Tikz_Style &boundary_style=tikz_path_style("orange!90!black"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute and insert alpha-shape for input points.
void put_funnel_trace_step(Tikz_Plane &plane, const Polygon &polygon, const Point &source, const Point &target, const FunnelTraceResult &trace, size_t step_index, const Tikz_Style &polygon_style=tikz_area_style("black", "gray!15", 0.22), const Tikz_Style &source_style=tikz_points_style("green!50!black"), const Tikz_Style &target_style=tikz_points_style("blue"), const Tikz_Style &all_portals_style=tikz_wire_style("purple", true), const Tikz_Style &active_portal_style=tikz_path_style("purple"), const Tikz_Style &funnel_leg_style=tikz_path_style("orange!90!black"), const Tikz_Style &committed_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int polygon_layer=Tikz_Plane::Layer_Default, const int portal_layer=Tikz_Plane::Layer_Foreground, const int highlight_layer=Tikz_Plane::Layer_Overlay)
Render one funnel-trace frame in a plane.
RangeTreeQueryVizResult visualize_range_tree_query(Tikz_Plane &plane, const RangeTree2D &tree, const Rectangle &query_rect, const bool draw_points=true, const Tikz_Style &split_style=tikz_wire_style("purple"), const Tikz_Style &point_style=tikz_points_style("black"), const Tikz_Style &query_rect_style=tikz_wire_style("red", true), const Tikz_Style &query_hit_style=tikz_points_style("red"))
Visualize range-tree plus a query rectangle and matching points.
PowerDiagram::Result visualize_power_diagram(Tikz_Plane &plane, const Array< PowerDiagram::WeightedSite > &sites, const PowerDiagram &algorithm={}, const bool draw_cells=true, const Tikz_Style &cell_style=tikz_area_style("violet", "violet!18", 0.35), const Tikz_Style &edge_style=tikz_wire_style("violet"), const Tikz_Style &site_style=tikz_points_style("purple"))
Compute and insert Power diagram for weighted sites.
DelaunayTriangulationBowyerWatson::Result visualize_delaunay(Tikz_Plane &plane, const DynList< Point > &points, const DelaunayTriangulationBowyerWatson &algorithm={}, const Tikz_Style &triangle_style=tikz_wire_style("blue"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute and insert Delaunay triangulation as triangle outlines.
VoronoiDiagram::Result visualize_voronoi(Tikz_Plane &plane, const DynList< Point > &sites, const VoronoiDiagram &algorithm={}, const bool draw_cells=false, const Tikz_Style &cell_style=tikz_area_style("gray!50!black", "gray!15", 0.35), const Tikz_Style &edge_style=tikz_wire_style("black"), const Tikz_Style &unbounded_edge_style=tikz_wire_style("black", true, true), const Tikz_Style &site_style=tikz_points_style("red"), const Geom_Number &unbounded_ray_length=Geom_Number(50))
Compute and insert Voronoi diagram for input sites.
RegularTriangulationBowyerWatson::Result visualize_regular_triangulation(Tikz_Plane &plane, const Array< RegularTriangulationBowyerWatson::WeightedSite > &weighted_sites, const RegularTriangulationBowyerWatson &algorithm={}, const Tikz_Style &triangle_style=tikz_wire_style("blue!60"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute and insert regular (weighted Delaunay) triangulation.
Polygon visualize_half_plane_intersection(Tikz_Plane &plane, const Array< HalfPlaneIntersection::HalfPlane > &halfplanes, const HalfPlaneIntersection &algorithm={}, const Tikz_Style &boundary_style=tikz_wire_style("gray!60", true, true), const Tikz_Style &result_style=tikz_area_style("red", "red!25", 0.50))
Compute and draw bounded half-plane intersection.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
RTree< Payload, MaxEntries, MinEntries, Variant >::DebugSnapshot visualize_rtree(Tikz_Plane &plane, const RTree< Payload, MaxEntries, MinEntries, Variant > &tree, const Tikz_Style &node_bbox_style=tikz_wire_style("teal!70!black"), const Tikz_Style &leaf_bbox_style=tikz_wire_style("blue!70"), const Tikz_Style &entry_bbox_style=tikz_wire_style("gray!55"))
Visualize an R-tree/R*-tree hierarchy (node MBRs by depth, plus leaf entry boxes).
Polygon visualize_visibility_polygon(Tikz_Plane &plane, const Polygon &polygon, const Point &query_point, const VisibilityPolygon &algorithm={}, const Tikz_Style &polygon_style=tikz_wire_style("black"), const Tikz_Style &visibility_style=tikz_area_style("orange!90!black", "orange!25", 0.50), const Tikz_Style &query_style=tikz_points_style("red"))
Compute and draw visibility polygon from a query point.
ShortestPathDebugResult visualize_shortest_path_with_portals(Tikz_Plane &plane, const Polygon &polygon, const Point &source, const Point &target, const ShortestPathInPolygon &algorithm={}, const Tikz_Style &polygon_style=tikz_area_style("black", "gray!15", 0.25), const Tikz_Style &source_style=tikz_points_style("green!50!black"), const Tikz_Style &target_style=tikz_points_style("blue"), const Tikz_Style &portal_style=tikz_wire_style("purple", true), const Tikz_Style &path_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int polygon_layer=Tikz_Plane::Layer_Default, const int portal_layer=Tikz_Plane::Layer_Foreground, const int path_layer=Tikz_Plane::Layer_Overlay)
Visualize the shortest path plus funnel portals.
Array< SweepLineSegmentIntersection::Intersection > visualize_line_sweep(Tikz_Plane &plane, const Array< Segment > &segments, const SweepLineSegmentIntersection &algorithm={}, const Tikz_Style &segment_style=tikz_wire_style("blue!60"), const Tikz_Style &intersection_style=tikz_points_style("red"))
Compute and draw Bentley-Ottmann line-sweep intersections.
KDTreePointSearch::DebugSnapshot visualize_kdtree_partitions(Tikz_Plane &plane, const KDTreePointSearch &kd_tree, const bool draw_partition_boxes=false, const bool draw_points=true, const Tikz_Style &partition_style=tikz_wire_style("gray!55", true), const Tikz_Style &split_style=tikz_wire_style("blue!70"), const Tikz_Style &point_style=tikz_points_style("red"))
Visualize KD-tree recursive space partitions.
mpq_class Geom_Number
Numeric type used by the geometry module.
DynList< Point > visualize_shortest_path_in_polygon(Tikz_Plane &plane, const Polygon &polygon, const Point &source, const Point &target, const ShortestPathInPolygon &algorithm={}, const Tikz_Style &polygon_style=tikz_area_style("black", "gray!15", 0.25), const Tikz_Style &source_style=tikz_points_style("green!50!black"), const Tikz_Style &target_style=tikz_points_style("blue"), const Tikz_Style &path_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int polygon_layer=Tikz_Plane::Layer_Default, const int path_layer=Tikz_Plane::Layer_Foreground)
Visualize the shortest path inside a simple polygon.
void error(const char *file, int line, const char *format,...)
Print an error message with file and line info.
ClosestPairDivideAndConquer::Result visualize_closest_pair(Tikz_Plane &plane, const DynList< Point > &points, const ClosestPairDivideAndConquer &algorithm={}, const Tikz_Style &points_style=tikz_points_style("black"), const Tikz_Style &pair_style=tikz_path_style("red"), const Tikz_Style &pair_points_style=tikz_points_style("red"))
Compute and draw the closest pair from an input point set.
RTreeQueryVizResult< Payload, MaxEntries, MinEntries, Variant > visualize_rtree_query(Tikz_Plane &plane, const RTree< Payload, MaxEntries, MinEntries, Variant > &tree, const Rectangle &query_rect, const Tikz_Style &node_bbox_style=tikz_wire_style("teal!70!black"), const Tikz_Style &leaf_bbox_style=tikz_wire_style("blue!70"), const Tikz_Style &entry_bbox_style=tikz_wire_style("gray!55"), const Tikz_Style &query_rect_style=tikz_wire_style("red", true), const Tikz_Style &query_hit_style=tikz_wire_style("red"))
Visualize an R-tree/R*-tree with a rectangle query overlay, highlighting every entry whose bbox inter...
RotatingCalipersResult visualize_rotating_calipers(Tikz_Plane &plane, const Polygon &polygon, const Tikz_Style &polygon_style=tikz_wire_style("gray!55"), const Tikz_Style &diameter_style=tikz_path_style("red"), const Tikz_Style &width_style=tikz_path_style("blue"), const Tikz_Style &witness_style=tikz_points_style("orange!90!black"))
Compute and draw rotating-calipers diameter and minimum width.
Tikz_Style tikz_wire_style(const std::string &color="black", const bool dashed=false, const bool with_arrow=false)
Creates a style optimized for wireframe segments and polygons.
SegmentArrangement::Result visualize_segment_arrangement(Tikz_Plane &plane, const Array< Segment > &segments, const SegmentArrangement &algorithm={}, const bool draw_faces=true, const bool draw_vertices=true, const bool draw_unbounded_face=false, const Tikz_Style &face_style=tikz_area_style("teal!60!black", "teal!12", 0.30), const Tikz_Style &edge_style=tikz_wire_style("teal!70!black"), const Tikz_Style &vertex_style=tikz_points_style("teal!70!black"), const bool color_faces_by_index=false)
Compute and insert arrangement for input segments.
Polygon visualize_minkowski_sum(Tikz_Plane &plane, const Polygon &first, const Polygon &second, const MinkowskiSumConvex &algorithm={}, const Tikz_Style &first_style=tikz_area_style("blue", "blue!14", 0.30), const Tikz_Style &second_style=tikz_area_style("green!60!black", "green!16", 0.30), const Tikz_Style &result_style=tikz_area_style("red", "red!26", 0.60))
Compute and draw Minkowski sum of two convex polygons.
FunnelTraceResult compute_shortest_path_funnel_trace(const Polygon &polygon, const Point &source, const Point &target)
Compute a full SSFA trace (portal-by-portal states).
DynList< Triangle > visualize_monotone_triangulation(Tikz_Plane &plane, const Polygon &polygon, const MonotonePolygonTriangulation &algorithm={}, const Tikz_Style &polygon_style=tikz_wire_style("black"), const Tikz_Style &triangle_style=tikz_wire_style("blue!65"))
Compute and draw triangulation via monotone partition pipeline.
Tikz_Style tikz_area_style(const std::string &draw_color="black", const std::string &fill_color="gray!25", const double opacity=0.6)
Creates a style for drawing filled polygons.
Polygon visualize_convex_hull(Tikz_Plane &plane, const DynList< Point > &points, const HullAlgorithm &hull_algorithm, const Tikz_Style &point_style=tikz_points_style("black", 0.6), const Tikz_Style &hull_style=tikz_wire_style("red"), const Tikz_Style &hull_vertex_style=tikz_points_style("red"), const int point_layer=Tikz_Plane::Layer_Default, const int hull_layer=Tikz_Plane::Layer_Foreground, const bool draw_hull_vertices=true)
Runs a convex hull algorithm and visualizes the result.
Tikz_Style tikz_points_style(const std::string &color="black", const double opacity=-1.0)
Creates a style optimized for point clouds.
Array< Polygon > visualize_convex_decomposition(Tikz_Plane &plane, const Polygon &polygon, const ConvexPolygonDecomposition &algorithm={}, const bool draw_input_polygon=true, const Tikz_Style &input_style=tikz_wire_style("black", true), const bool color_parts_by_index=true, const Tikz_Style &part_style=tikz_area_style("blue!60!black", "blue!15", 0.40), const int input_layer=Tikz_Plane::Layer_Default, const int part_layer=Tikz_Plane::Layer_Foreground)
Compute and insert convex decomposition for a polygon.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
static struct argp_option options[]
Full trace for shortest-path funnel processing.
Options used by Tikz_Scene beamer/handout export helpers.
std::string frame_title
Frame title used by scene exports.
std::string class_options
beamer class options (for example aspectratio=169).
std::string frame_options
Frame options passed to \\begin{frame}[...].
double max_picture_height_mm
Maximum rendered picture height in millimeters.
Options used by Tikz_Scene standalone document export.
std::string class_options
Style descriptor for TikZ primitives.
std::string pattern
TikZ pattern (e.g. north east lines)
std::string pattern_color
TikZ pattern color (pattern color=<color>)
Aleph::Array< Display_Node > nodes
Root at index zero.
Helpers to visualize computational-geometry algorithm results in TikZ.
High-level scene management for TikZ geometry visualization.
R*-tree: an R-tree tuned with the Beckmann-Kriegel-Schneider-Seeger heuristics.