1#include <gtest/gtest.h>
21 return s.find(
"nan") != std::string::npos
or
22 s.find(
"inf") != std::string::npos;
129 std::ostringstream
output;
131 const std::string result =
output.str();
133 const size_t green_pos = result.find(
"draw=green");
134 const size_t red_pos = result.find(
"draw=red");
162 std::ostringstream
output;
164 const std::string result =
output.str();
166 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
180 std::ostringstream
output;
182 const std::string result =
output.str();
184 EXPECT_NE(result.find(
"fill=red!30"), std::string::npos);
202 std::ostringstream
output;
204 const std::string result =
output.str();
206 EXPECT_NE(result.find(
"dashed"), std::string::npos);
227 std::ostringstream
output;
229 const std::string result =
output.str();
230 EXPECT_NE(result.find(
"draw=blue"), std::string::npos);
247 std::ostringstream
output;
249 const std::string result =
output.str();
251 EXPECT_NE(result.find(
"violet"), std::string::npos);
274 std::ostringstream
output;
276 const std::string result =
output.str();
278 EXPECT_NE(result.find(
"teal!70!black"), std::string::npos);
302 std::ostringstream
output;
304 const std::string result =
output.str();
306 EXPECT_NE(result.find(
"blue!20"), std::string::npos);
313 const Point source(2, 16);
314 const Point target(18, 16);
322 std::ostringstream
output;
324 const std::string result =
output.str();
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);
350 std::ostringstream
output;
352 const std::string result =
output.str();
354 EXPECT_NE(result.find(
"orange!90!black"), std::string::npos);
373 std::ostringstream
output;
375 const std::string result =
output.str();
376 EXPECT_NE(result.find(
"blue!60"), std::string::npos);
394 std::ostringstream
output;
396 const std::string result =
output.str();
397 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
411 std::ostringstream
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);
429 std::ostringstream
output;
431 const std::string result =
output.str();
432 EXPECT_NE(result.find(
"fill=red!25"), std::string::npos);
455 std::ostringstream
output;
457 const std::string result =
output.str();
458 EXPECT_NE(result.find(
"fill=red!26"), std::string::npos);
473 std::ostringstream
output;
475 const std::string result =
output.str();
476 EXPECT_NE(result.find(
"blue!65"), std::string::npos);
483 const Point query(2, 16);
489 std::ostringstream
output;
491 const std::string result =
output.str();
492 EXPECT_NE(result.find(
"orange!90!black"), std::string::npos);
508 std::ostringstream
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);
532 std::ostringstream
output;
534 const std::string result =
output.str();
535 EXPECT_NE(result.find(
"fill=red"), std::string::npos);
558 std::ostringstream
output;
560 const std::string result =
output.str();
561 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
581 std::ostringstream
output;
583 const std::string result =
output.str();
584 EXPECT_NE(result.find(
"draw=red"), std::string::npos);
591 const Point source(2, 16);
592 const Point target(18, 16);
601 std::ostringstream
output;
603 const std::string result =
output.str();
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);
623 std::ostringstream
output;
625 const std::string result =
output.str();
627 EXPECT_NE(result.find(
"blue!20"), std::string::npos);
634 const Point source(2, 16);
635 const Point target(18, 16);
650 const Point source(2, 16);
651 const Point target(18, 16);
660 std::ostringstream
output;
662 const std::string result =
output.str();
664 EXPECT_NE(result.find(
"draw=purple"), std::string::npos);
665 EXPECT_NE(result.find(
"draw=orange!90!black"), std::string::npos);
677 scene.put_cartesian_axis()
678 .set_point_radius_mm(0.65);
692 for (
size_t i = 0; i <
arrangement.vertices.size(); ++i)
707 const std::string
tikz =
scene.to_tikz();
708 EXPECT_NE(
tikz.find(
"draw=teal!70!black"), std::string::npos);
724 const auto dt =
scene.visualize_delaunay(points);
727 const auto cp =
scene.visualize_closest_pair(points);
751 const auto rv =
scene.visualize_range_tree_query(
760 const auto av =
scene.visualize_aabb_tree_query(
764 const std::string
tikz =
scene.to_tikz();
779 EXPECT_NE(
latex.find(
"\\documentclass[tikz,border=6pt]{standalone}"),
781 EXPECT_NE(
latex.find(
"}\n\\usepackage{tikz}\n"), std::string::npos);
782 EXPECT_EQ(
latex.find(
"}\\n\\usepackage{tikz}\\n"), std::string::npos);
796 opts.frame_title =
"Scene Demo";
797 opts.frame_options =
"t";
803 EXPECT_NE(
latex.find(
"\\setbeamertemplate{navigation symbols}{}"),
805 EXPECT_NE(
latex.find(
"\\begin{frame}[t]{Scene Demo}"), std::string::npos);
807 EXPECT_EQ(
latex.find(
"\\documentclass[handout,aspectratio=43]{beamer}"),
819 opts.frame_title =
"Handout Demo";
823 EXPECT_NE(
latex.find(
"\\documentclass[handout,aspectratio=169]{beamer}"),
825 EXPECT_NE(
latex.find(
"\\begin{frame}[t]{Handout Demo}"), std::string::npos);
828 opts.class_options =
"handout,aspectratio=169";
837 std::vector<Tikz_Scene> steps;
838 steps.emplace_back(120, 80, 0, 0,
true);
840 steps.emplace_back(120, 80, 0, 0,
true);
845 opts.frame_title =
"Overlay Demo";
846 opts.frame_options =
"t";
852 EXPECT_NE(
latex.find(
"\\begin{frame}[t]{Overlay Demo}"), std::string::npos);
856 EXPECT_EQ(
latex.find(
"\\documentclass[handout,aspectratio=169]{beamer}"),
863 std::vector<Tikz_Scene> steps;
864 steps.emplace_back(120, 80, 0, 0,
true);
869 opts.frame_title =
"Overlay Handout";
872 EXPECT_NE(
latex.find(
"\\documentclass[handout,aspectratio=43]{beamer}"),
881 const std::vector<Tikz_Scene> steps;
884 EXPECT_NE(
latex.find(
"No overlays provided."), std::string::npos);
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.
Iterator on the items of list.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
bool has_curr() const noexcept
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.
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.
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.
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.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
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.
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.
std::string class_options
Style descriptor for TikZ primitives.
Helpers to visualize computational-geometry algorithm results in TikZ.