Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tikzgeom_algorithms_test.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
3#include <cctype>
4#include <sstream>
5#include <string>
6#include <vector>
7
9#include <tikzgeom_scene.H>
10
11using namespace Aleph;
12
13namespace
14{
15
16bool has_nan_or_inf(std::string s)
17{
18 for (char & c : s)
20
21 return s.find("nan") != std::string::npos or
22 s.find("inf") != std::string::npos;
23}
24
26{
27 Polygon p;
28 p.add_vertex(Point(-20, -10));
29 p.add_vertex(Point(10, -12));
30 p.add_vertex(Point(18, 4));
31 p.add_vertex(Point(-8, 18));
32 p.close();
33 return p;
34}
35
37{
38 Polygon p;
39 p.add_vertex(Point(-14, -18));
40 p.add_vertex(Point(22, -2));
41 p.add_vertex(Point(8, 22));
42 p.add_vertex(Point(-18, 8));
43 p.close();
44 return p;
45}
46
48{
49 Polygon p;
50 p.add_vertex(Point(0, 0));
51 p.add_vertex(Point(20, 0));
52 p.add_vertex(Point(20, 20));
53 p.add_vertex(Point(12, 20));
54 p.add_vertex(Point(12, 8));
55 p.add_vertex(Point(8, 8));
56 p.add_vertex(Point(8, 20));
57 p.add_vertex(Point(0, 20));
58 p.close();
59 return p;
60}
61
63{
64 Polygon p;
65 p.add_vertex(Point(0, 0));
66 p.add_vertex(Point(12, 0));
67 p.add_vertex(Point(12, 10));
68 p.add_vertex(Point(7, 10));
69 p.add_vertex(Point(7, 4));
70 p.add_vertex(Point(4, 4));
71 p.add_vertex(Point(4, 10));
72 p.add_vertex(Point(0, 10));
73 p.close();
74 return p;
75}
76
78{
79 Polygon p;
80 p.add_vertex(Point(-10, -4));
81 p.add_vertex(Point(10, -6));
82 p.add_vertex(Point(16, 2));
83 p.add_vertex(Point(7, 12));
84 p.add_vertex(Point(-8, 10));
85 p.close();
86 return p;
87}
88
90{
91 Polygon p;
92 p.add_vertex(Point(0, 0));
93 p.add_vertex(Point(20, 0));
94 p.add_vertex(Point(20, 18));
95 p.add_vertex(Point(11, 18));
96 p.add_vertex(Point(11, 8));
97 p.add_vertex(Point(7, 8));
98 p.add_vertex(Point(7, 18));
99 p.add_vertex(Point(0, 18));
100 p.close();
101 return p;
102}
103
104size_t count_points(const DynList<Point> & pts)
105{
106 size_t n = 0;
107 for (DynList<Point>::Iterator it(pts); it.has_curr(); it.next_ne())
108 ++n;
109 return n;
110}
111
112size_t count_points(const Array<Point> & pts)
113{
114 return pts.size();
115}
116
117} // namespace
118
120{
121 Tikz_Plane plane(100, 60);
122
124 Tikz_Style front = tikz_wire_style("red");
125
126 put_in_plane(plane, Segment(Point(0, 0), Point(50, 50)), front, 10);
127 put_in_plane(plane, Segment(Point(0, 50), Point(50, 0)), back, -10);
128
129 std::ostringstream output;
130 plane.draw(output);
131 const std::string result = output.str();
132
133 const size_t green_pos = result.find("draw=green");
134 const size_t red_pos = result.find("draw=red");
135
136 ASSERT_NE(green_pos, std::string::npos);
137 ASSERT_NE(red_pos, std::string::npos);
139}
140
142{
144 pts.append(Point(-15, -8));
145 pts.append(Point(-8, 10));
146 pts.append(Point(0, -10));
147 pts.append(Point(8, 8));
148 pts.append(Point(14, -3));
149 pts.append(Point(2, 16));
150
151 Tikz_Plane plane(120, 80);
153
155 plane, pts, hull_algo,
156 tikz_points_style("black"),
157 tikz_wire_style("red"),
158 tikz_points_style("red"));
159
160 EXPECT_GE(hull.size(), 3U);
161
162 std::ostringstream output;
163 plane.draw(output);
164 const std::string result = output.str();
165
166 EXPECT_NE(result.find("draw=red"), std::string::npos);
168}
169
171{
172 const Polygon a = make_convex_a();
173 const Polygon b = make_convex_b();
174
175 Tikz_Plane plane(120, 80);
177
178 EXPECT_GT(inter.size(), 0U);
179
180 std::ostringstream output;
181 plane.draw(output);
182 const std::string result = output.str();
183
184 EXPECT_NE(result.find("fill=red!30"), std::string::npos);
186}
187
189{
190 DynList<Point> sites;
191 sites.append(Point(-18, -8));
192 sites.append(Point(-6, 14));
193 sites.append(Point(8, -10));
194 sites.append(Point(16, 9));
195 sites.append(Point(2, 20));
196
197 Tikz_Plane plane(150, 100);
198 const auto vor = visualize_voronoi(plane, sites, VoronoiDiagram(), true);
199
200 EXPECT_EQ(vor.sites.size(), 5U);
201
202 std::ostringstream output;
203 plane.draw(output);
204 const std::string result = output.str();
205
206 EXPECT_NE(result.find("dashed"), std::string::npos);
208}
209
211{
212 DynList<Point> points;
213 points.append(Point(-12, -8));
214 points.append(Point(-8, 9));
215 points.append(Point(0, 14));
216 points.append(Point(11, 9));
217 points.append(Point(14, -7));
218 points.append(Point(2, -13));
219 points.append(Point(0, 0));
220
221 Tikz_Plane plane(160, 110);
222 const auto dt = visualize_delaunay(plane, points);
223
224 EXPECT_GE(dt.sites.size(), 5U);
225 EXPECT_GT(dt.triangles.size(), 0U);
226
227 std::ostringstream output;
228 plane.draw(output);
229 const std::string result = output.str();
230 EXPECT_NE(result.find("draw=blue"), std::string::npos);
232}
233
235{
237 sites.append({Point(-16, -6), Geom_Number(1)});
238 sites.append({Point(-2, 12), Geom_Number(4)});
239 sites.append({Point(12, -8), Geom_Number(2)});
240 sites.append({Point(18, 10), Geom_Number(6)});
241
242 Tikz_Plane plane(150, 100);
243 const auto pd = visualize_power_diagram(plane, sites);
244
245 EXPECT_EQ(pd.sites.size(), 4U);
246
247 std::ostringstream output;
248 plane.draw(output);
249 const std::string result = output.str();
250
251 EXPECT_NE(result.find("violet"), std::string::npos);
253}
254
256{
257 Array<Segment> segments;
258 segments.append(Segment(Point(-20, 0), Point(20, 0)));
259 segments.append(Segment(Point(0, -20), Point(0, 20)));
260 segments.append(Segment(Point(-20, -20), Point(20, 20)));
261
262 Tikz_Plane plane(150, 100);
264 plane, segments, SegmentArrangement(),
265 true, true, false,
266 tikz_area_style("teal!60!black", "teal!12", 0.30),
267 tikz_wire_style("teal!70!black"),
268 tikz_points_style("teal!70!black"),
269 true);
270
271 EXPECT_GT(arrangement.vertices.size(), 4U);
272 EXPECT_GT(arrangement.edges.size(), 3U);
273
274 std::ostringstream output;
275 plane.draw(output);
276 const std::string result = output.str();
277
278 EXPECT_NE(result.find("teal!70!black"), std::string::npos);
280}
281
283{
284 Array<Segment> segments;
285 segments.append(Segment(Point(0, 0), Point(20, 0)));
286 segments.append(Segment(Point(20, 0), Point(20, 20)));
287 segments.append(Segment(Point(20, 20), Point(0, 20)));
288 segments.append(Segment(Point(0, 20), Point(0, 0)));
289 segments.append(Segment(Point(0, 0), Point(20, 20)));
290
291 Tikz_Plane plane(150, 100);
293 plane, segments, SegmentArrangement(),
294 true, true, false,
295 tikz_area_style("teal!60!black", "teal!12", 0.30),
296 tikz_wire_style("teal!70!black"),
297 tikz_points_style("teal!70!black"),
298 true);
299
300 EXPECT_GT(arrangement.faces.size(), 1U);
301
302 std::ostringstream output;
303 plane.draw(output);
304 const std::string result = output.str();
305
306 EXPECT_NE(result.find("blue!20"), std::string::npos);
308}
309
311{
312 const Polygon polygon = make_shortest_path_polygon();
313 const Point source(2, 16);
314 const Point target(18, 16);
315
316 Tikz_Plane plane(170, 110);
317 const auto path = visualize_shortest_path_in_polygon(
318 plane, polygon, source, target, ShortestPathInPolygon());
319
320 EXPECT_GE(count_points(path), 2U);
321
322 std::ostringstream output;
323 plane.draw(output);
324 const std::string result = output.str();
325
326 EXPECT_NE(result.find("draw=red"), std::string::npos);
327 EXPECT_NE(result.find("fill=green!50!black"), std::string::npos);
328 EXPECT_NE(result.find("fill=blue"), std::string::npos);
330}
331
333{
334 DynList<Point> points;
335 points.append(Point(-12, -8));
336 points.append(Point(-10, 9));
337 points.append(Point(-1, 14));
338 points.append(Point(10, 10));
339 points.append(Point(13, -7));
340 points.append(Point(0, -13));
341 points.append(Point(0, 0));
342
343 Tikz_Plane plane(170, 110);
345 plane, points, Geom_Number(10000), AlphaShape(),
346 true);
347
348 EXPECT_GT(alpha_shape.boundary_edges.size(), 0U);
349
350 std::ostringstream output;
351 plane.draw(output);
352 const std::string result = output.str();
353
354 EXPECT_NE(result.find("orange!90!black"), std::string::npos);
356}
357
359{
361 sites.append({Point(-10, -6), Geom_Number(0)});
362 sites.append({Point(-2, 10), Geom_Number(2)});
363 sites.append({Point(10, -4), Geom_Number(1)});
364 sites.append({Point(15, 8), Geom_Number(3)});
365 sites.append({Point(2, -12), Geom_Number(0)});
366
367 Tikz_Plane plane(160, 110);
368 const auto rt = visualize_regular_triangulation(plane, sites);
369
370 EXPECT_GE(rt.sites.size(), 4U);
371 EXPECT_GT(rt.triangles.size(), 0U);
372
373 std::ostringstream output;
374 plane.draw(output);
375 const std::string result = output.str();
376 EXPECT_NE(result.find("blue!60"), std::string::npos);
378}
379
381{
382 DynList<Point> points;
383 points.append(Point(-12, -8));
384 points.append(Point(-2, 5));
385 points.append(Point(1, 7));
386 points.append(Point(2, 7));
387 points.append(Point(10, -6));
388
389 Tikz_Plane plane(150, 100);
390 const auto cp = visualize_closest_pair(plane, points);
391
392 EXPECT_TRUE(cp.distance_squared >= 0);
393
394 std::ostringstream output;
395 plane.draw(output);
396 const std::string result = output.str();
397 EXPECT_NE(result.find("draw=red"), std::string::npos);
399}
400
402{
403 const Polygon poly = make_convex_for_calipers();
404 Tikz_Plane plane(160, 110);
405
406 const auto rc = visualize_rotating_calipers(plane, poly);
407
408 EXPECT_TRUE(rc.diameter.distance_squared > 0);
409 EXPECT_TRUE(rc.width.width_squared >= 0);
410
411 std::ostringstream output;
412 plane.draw(output);
413 const std::string result = output.str();
414 EXPECT_NE(result.find("draw=red"), std::string::npos);
415 EXPECT_NE(result.find("draw=blue"), std::string::npos);
417}
418
420{
423
424 Tikz_Plane plane(160, 110);
426
427 EXPECT_GT(inter.size(), 0U);
428
429 std::ostringstream output;
430 plane.draw(output);
431 const std::string result = output.str();
432 EXPECT_NE(result.find("fill=red!25"), std::string::npos);
434}
435
437{
438 Polygon p;
439 p.add_vertex(Point(-4, -2));
440 p.add_vertex(Point(3, -2));
441 p.add_vertex(Point(1, 4));
442 p.close();
443
444 Polygon q;
445 q.add_vertex(Point(-3, -1));
446 q.add_vertex(Point(2, -1));
447 q.add_vertex(Point(0, 3));
448 q.close();
449
450 Tikz_Plane plane(160, 110);
451 const Polygon sum = visualize_minkowski_sum(plane, p, q);
452
453 EXPECT_GT(sum.size(), 0U);
454
455 std::ostringstream output;
456 plane.draw(output);
457 const std::string result = output.str();
458 EXPECT_NE(result.find("fill=red!26"), std::string::npos);
460}
461
463{
465 Tikz_Plane plane(170, 110);
466
468 size_t tri_count = 0;
469 for (DynList<Triangle>::Iterator it(tris); it.has_curr(); it.next_ne())
470 ++tri_count;
472
473 std::ostringstream output;
474 plane.draw(output);
475 const std::string result = output.str();
476 EXPECT_NE(result.find("blue!65"), std::string::npos);
478}
479
481{
482 const Polygon polygon = make_visibility_polygon();
483 const Point query(2, 16);
484
485 Tikz_Plane plane(170, 110);
486 const Polygon vis = visualize_visibility_polygon(plane, polygon, query);
487 EXPECT_GT(vis.size(), 0U);
488
489 std::ostringstream output;
490 plane.draw(output);
491 const std::string result = output.str();
492 EXPECT_NE(result.find("orange!90!black"), std::string::npos);
494}
495
497{
498 Array<Segment> segments;
499 segments.append(Segment(Point(-15, -8), Point(15, 10)));
500 segments.append(Segment(Point(-12, 11), Point(14, -7)));
501 segments.append(Segment(Point(-15, 2), Point(15, 2)));
502
503 Tikz_Plane plane(170, 110);
504 const auto intersections = visualize_line_sweep(plane, segments);
505
506 EXPECT_GT(intersections.size(), 0U);
507
508 std::ostringstream output;
509 plane.draw(output);
510 const std::string result = output.str();
511 EXPECT_NE(result.find("blue!60"), std::string::npos);
512 EXPECT_NE(result.find("fill=red"), std::string::npos);
514}
515
517{
518 Array<Point> points;
519 points.append(Point(10, 10));
520 points.append(Point(20, 30));
521 points.append(Point(50, 40));
522 points.append(Point(70, 80));
523 points.append(Point(90, 20));
524 const auto kd = KDTreePointSearch::build(points, 0, 0, 100, 100);
525
526 Tikz_Plane plane(180, 110);
527 const auto snap = visualize_kdtree_partitions(plane, kd, true, true);
528
529 EXPECT_EQ(snap.points.size(), points.size());
530 EXPECT_GT(snap.partitions.size(), 0U);
531
532 std::ostringstream output;
533 plane.draw(output);
534 const std::string result = output.str();
535 EXPECT_NE(result.find("fill=red"), std::string::npos);
537}
538
540{
541 DynList<Point> points;
542 points.append(Point(1, 1));
543 points.append(Point(3, 5));
544 points.append(Point(4, 4));
545 points.append(Point(7, 2));
546 points.append(Point(9, 8));
547
548 RangeTree2D tree;
549 tree.build(points);
550
551 Tikz_Plane plane(180, 110);
552 const auto viz = visualize_range_tree_query(
553 plane, tree, Rectangle(2, 1, 6, 5));
554
555 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
556 EXPECT_GT(viz.query_hits.size(), 0U);
557
558 std::ostringstream output;
559 plane.draw(output);
560 const std::string result = output.str();
561 EXPECT_NE(result.find("draw=red"), std::string::npos);
563}
564
566{
567 AABBTree tree;
569 entries.append({Rectangle(0, 0, 5, 5), 0});
570 entries.append({Rectangle(3, 3, 8, 8), 1});
571 entries.append({Rectangle(10, 10, 15, 15), 2});
572 tree.build(entries);
573
574 Tikz_Plane plane(180, 110);
575 const auto viz = visualize_aabb_tree_query(
576 plane, tree, Rectangle(2, 2, 6, 6));
577
578 EXPECT_GT(viz.snapshot.nodes.size(), 0U);
579 EXPECT_GT(viz.query_hit_ids.size(), 0U);
580
581 std::ostringstream output;
582 plane.draw(output);
583 const std::string result = output.str();
584 EXPECT_NE(result.find("draw=red"), std::string::npos);
586}
587
589{
590 const Polygon polygon = make_shortest_path_polygon();
591 const Point source(2, 16);
592 const Point target(18, 16);
593
594 Tikz_Plane plane(170, 110);
596 plane, polygon, source, target, ShortestPathInPolygon());
597
598 EXPECT_GE(debug.portals.size(), 2U);
599 EXPECT_GE(count_points(debug.path), 2U);
600
601 std::ostringstream output;
602 plane.draw(output);
603 const std::string result = output.str();
604
605 EXPECT_NE(result.find("draw=purple"), std::string::npos);
606 EXPECT_NE(result.find("dashed"), std::string::npos);
607 EXPECT_NE(result.find("draw=red"), std::string::npos);
609}
610
612{
614
615 Tikz_Plane plane(170, 110);
618 true, tikz_wire_style("black", true),
619 true);
620
621 EXPECT_GT(parts.size(), 1U);
622
623 std::ostringstream output;
624 plane.draw(output);
625 const std::string result = output.str();
626
627 EXPECT_NE(result.find("blue!20"), std::string::npos);
629}
630
632{
633 const Polygon polygon = make_shortest_path_polygon();
634 const Point source(2, 16);
635 const Point target(18, 16);
636
638 compute_shortest_path_funnel_trace(polygon, source, target);
639
640 EXPECT_GE(trace.portals.size(), 2U);
641 EXPECT_GT(trace.steps.size(), 0U);
642 EXPECT_GE(count_points(trace.final_path), 2U);
643 EXPECT_EQ(trace.final_path(0), source);
644 EXPECT_EQ(trace.final_path(trace.final_path.size() - 1), target);
645}
646
648{
649 const Polygon polygon = make_shortest_path_polygon();
650 const Point source(2, 16);
651 const Point target(18, 16);
652
654 compute_shortest_path_funnel_trace(polygon, source, target);
655 ASSERT_GT(trace.steps.size(), 0U);
656
657 Tikz_Plane plane(170, 110);
658 put_funnel_trace_step(plane, polygon, source, target, trace, 0);
659
660 std::ostringstream output;
661 plane.draw(output);
662 const std::string result = output.str();
663
664 EXPECT_NE(result.find("draw=purple"), std::string::npos);
665 EXPECT_NE(result.find("draw=orange!90!black"), std::string::npos);
667}
668
670{
671 Array<Segment> segments;
672 segments.append(Segment(Point(-20, 0), Point(20, 0)));
673 segments.append(Segment(Point(0, -20), Point(0, 20)));
674 segments.append(Segment(Point(-18, -14), Point(18, 14)));
675
676 Tikz_Scene scene(190, 120, 0, 0, true);
677 scene.put_cartesian_axis()
678 .set_point_radius_mm(0.65);
679
680 const auto arrangement = scene.visualize_segment_arrangement(
681 segments,
683 true,
684 true,
685 false,
686 tikz_area_style("teal!60!black", "teal!12", 0.30),
687 tikz_wire_style("teal!70!black"),
688 tikz_points_style("teal!70!black"),
689 true);
690
692 for (size_t i = 0; i < arrangement.vertices.size(); ++i)
694
695 const Polygon hull = scene.visualize_convex_hull(
698 tikz_points_style("black"),
699 tikz_wire_style("red"),
700 tikz_points_style("red"),
703 true);
704
705 EXPECT_GE(hull.size(), 3U);
706
707 const std::string tikz = scene.to_tikz();
708 EXPECT_NE(tikz.find("draw=teal!70!black"), std::string::npos);
709 EXPECT_NE(tikz.find("draw=red"), std::string::npos);
711}
712
714{
715 Tikz_Scene scene(190, 120, 0, 0, true);
716
717 DynList<Point> points;
718 points.append(Point(-10, -7));
719 points.append(Point(-2, 9));
720 points.append(Point(8, -6));
721 points.append(Point(12, 8));
722 points.append(Point(0, 0));
723
724 const auto dt = scene.visualize_delaunay(points);
725 EXPECT_GT(dt.triangles.size(), 0U);
726
727 const auto cp = scene.visualize_closest_pair(points);
728 EXPECT_TRUE(cp.distance_squared >= 0);
729
730 Array<Segment> segments;
731 segments.append(Segment(Point(-12, -8), Point(12, 10)));
732 segments.append(Segment(Point(-12, 10), Point(12, -8)));
733 const auto intersections = scene.visualize_line_sweep(segments);
734 EXPECT_GT(intersections.size(), 0U);
735
737 kd_points.append(Point(5, 5));
738 kd_points.append(Point(15, 20));
739 kd_points.append(Point(35, 10));
740 kd_points.append(Point(45, 30));
741 const auto kd = KDTreePointSearch::build(kd_points, 0, 0, 50, 40);
742 const auto kd_snap = scene.visualize_kdtree_partitions(kd);
743 EXPECT_GT(kd_snap.partitions.size(), 0U);
744
748 range_points.append(Point(3, 4));
749 range_points.append(Point(6, 2));
751 const auto rv = scene.visualize_range_tree_query(
752 range_tree, Rectangle(0, 0, 4, 5));
753 EXPECT_GT(rv.query_hits.size(), 0U);
754
757 aabb_entries.append({Rectangle(0, 0, 4, 4), 0});
758 aabb_entries.append({Rectangle(2, 2, 8, 8), 1});
759 aabb_tree.build(aabb_entries);
760 const auto av = scene.visualize_aabb_tree_query(
761 aabb_tree, Rectangle(1, 1, 3, 3));
762 EXPECT_GT(av.query_hit_ids.size(), 0U);
763
764 const std::string tikz = scene.to_tikz();
765 EXPECT_NE(tikz.find("draw=blue"), std::string::npos);
766 EXPECT_NE(tikz.find("draw=red"), std::string::npos);
768}
769
771{
772 Tikz_Scene scene(120, 80, 2, 3, true);
773 scene.add(Segment(Point(0, 0), Point(10, 15)), tikz_wire_style("blue"));
774
776 opts.class_options = "tikz,border=6pt";
777 const std::string latex = scene.to_standalone(opts);
778
779 EXPECT_NE(latex.find("\\documentclass[tikz,border=6pt]{standalone}"),
780 std::string::npos);
781 EXPECT_NE(latex.find("}\n\\usepackage{tikz}\n"), std::string::npos);
782 EXPECT_EQ(latex.find("}\\n\\usepackage{tikz}\\n"), std::string::npos);
783 EXPECT_NE(latex.find("\\usepackage{tikz}"), std::string::npos);
784 EXPECT_NE(latex.find("\\begin{tikzpicture}"), std::string::npos);
785 EXPECT_NE(latex.find("\\end{document}"), std::string::npos);
787}
788
790{
791 Tikz_Scene scene(120, 80, 2, 3, true);
792 scene.add(Segment(Point(0, 0), Point(10, 15)), tikz_wire_style("blue"));
793
795 opts.class_options = "aspectratio=43";
796 opts.frame_title = "Scene Demo";
797 opts.frame_options = "t";
798
799 const std::string latex = scene.to_beamer(opts);
800
801 EXPECT_NE(latex.find("\\documentclass[aspectratio=43]{beamer}"),
802 std::string::npos);
803 EXPECT_NE(latex.find("\\setbeamertemplate{navigation symbols}{}"),
804 std::string::npos);
805 EXPECT_NE(latex.find("\\begin{frame}[t]{Scene Demo}"), std::string::npos);
806 EXPECT_NE(latex.find("\\begin{tikzpicture}"), std::string::npos);
807 EXPECT_EQ(latex.find("\\documentclass[handout,aspectratio=43]{beamer}"),
808 std::string::npos);
810}
811
813{
814 Tikz_Scene scene(120, 80, 0, 0, true);
815 scene.add(Point(1, 1), tikz_points_style("red"));
816
818 opts.class_options = "aspectratio=169";
819 opts.frame_title = "Handout Demo";
820
821 const std::string latex = scene.to_handout(opts);
822
823 EXPECT_NE(latex.find("\\documentclass[handout,aspectratio=169]{beamer}"),
824 std::string::npos);
825 EXPECT_NE(latex.find("\\begin{frame}[t]{Handout Demo}"), std::string::npos);
827
828 opts.class_options = "handout,aspectratio=169";
829 const std::string latex_no_dup = scene.to_handout(opts);
830 EXPECT_NE(latex_no_dup.find("\\documentclass[handout,aspectratio=169]{beamer}"),
831 std::string::npos);
832 EXPECT_EQ(latex_no_dup.find("handout,handout"), std::string::npos);
833}
834
836{
837 std::vector<Tikz_Scene> steps;
838 steps.emplace_back(120, 80, 0, 0, true);
839 steps.back().add(Point(2, 3), tikz_points_style("red"));
840 steps.emplace_back(120, 80, 0, 0, true);
841 steps.back().add(Segment(Point(0, 0), Point(12, 9)), tikz_wire_style("blue"));
842
844 opts.class_options = "aspectratio=169";
845 opts.frame_title = "Overlay Demo";
846 opts.frame_options = "t";
847
848 const std::string latex = Tikz_Scene::to_beamer_overlays(steps, opts);
849
850 EXPECT_NE(latex.find("\\documentclass[aspectratio=169]{beamer}"),
851 std::string::npos);
852 EXPECT_NE(latex.find("\\begin{frame}[t]{Overlay Demo}"), std::string::npos);
853 EXPECT_NE(latex.find("\\only<1>{"), std::string::npos);
854 EXPECT_NE(latex.find("\\only<2>{"), std::string::npos);
855 EXPECT_EQ(latex.find("\\only<3>{"), std::string::npos);
856 EXPECT_EQ(latex.find("\\documentclass[handout,aspectratio=169]{beamer}"),
857 std::string::npos);
859}
860
862{
863 std::vector<Tikz_Scene> steps;
864 steps.emplace_back(120, 80, 0, 0, true);
865 steps.back().add(Point(4, 5), tikz_points_style("black"));
866
868 opts.class_options = "handout,aspectratio=43";
869 opts.frame_title = "Overlay Handout";
870
871 const std::string latex = Tikz_Scene::to_handout_overlays(steps, opts);
872 EXPECT_NE(latex.find("\\documentclass[handout,aspectratio=43]{beamer}"),
873 std::string::npos);
874 EXPECT_EQ(latex.find("handout,handout"), std::string::npos);
875 EXPECT_NE(latex.find("\\only<1>{"), std::string::npos);
877}
878
880{
881 const std::vector<Tikz_Scene> steps;
882 const std::string latex = Tikz_Scene::to_beamer_overlays(steps);
883
884 EXPECT_NE(latex.find("No overlays provided."), std::string::npos);
885 EXPECT_EQ(latex.find("\\only<1>{"), std::string::npos);
887}
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.
Definition tpl_array.H:139
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
Definition tpl_array.H:351
T & append(const T &data)
Append a copy of data
Definition tpl_array.H:245
Decompose a simple polygon into convex parts using Hertel-Mehlhorn.
Iterator on the items of list.
Definition htlist.H:1420
Dynamic singly linked list with functional programming support.
Definition htlist.H:1155
T & append(const T &item)
Definition htlist.H:1271
bool has_curr() const noexcept
Definition htlist.H:930
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.
Definition point.H:229
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:246
void add_vertex(const Point &point)
Add a vertex to the polygon.
Definition polygon.H:677
void close()
Close the polygon.
Definition polygon.H:840
const size_t & size() const
Get the number of vertices.
Definition polygon.H:477
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.
Definition point.H:1737
Compute the full planar subdivision induced by a set of segments.
Represents a line segment between two points.
Definition point.H:827
Compute the shortest Euclidean path between two points inside a simple polygon.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
Definition tikzgeom.H:184
void draw(std::ostream &output, const bool squarize=true) const
Emit a complete tikzpicture with all inserted objects.
Definition tikzgeom.H:1383
static constexpr int Layer_Default
Definition tikzgeom.H:187
static constexpr int Layer_Overlay
Definition tikzgeom.H:189
High-level scene wrapper to compose objects and algorithm visualizations.
static std::string to_handout_overlays(const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
String variant of draw_handout_overlays.
static std::string to_beamer_overlays(const std::vector< Tikz_Scene > &steps, const Tikz_Beamer_Document_Options &options={})
String variant of draw_beamer_overlays.
O(n log n) Voronoi diagram construction.
#define TEST(name)
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
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.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
Definition tikzgeom.H:1456
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.
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.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
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.
Definition point.H:115
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.
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.
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.
Full trace for shortest-path funnel processing.
Options used by Tikz_Scene beamer/handout export helpers.
std::string class_options
beamer class options (for example aspectratio=169).
Options used by Tikz_Scene standalone document export.
Style descriptor for TikZ primitives.
Definition tikzgeom.H:86
Helpers to visualize computational-geometry algorithm results in TikZ.
ofstream output
Definition writeHeap.C:215