31# ifndef TIKZGEOM_ALGORITHMS_H
32# define TIKZGEOM_ALGORITHMS_H
43 static const char *
colors[] =
45 "blue!20",
"orange!25",
"green!20",
"red!20",
"cyan!22",
46 "magenta!20",
"yellow!28",
"teal!22",
"lime!24",
"brown!20"
69 for (
size_t i = 0; i <
pts.size(); ++i)
70 if (
pts(i) == p)
return i;
101 for (
int e = 0; e < 3; ++e)
103 size_t u =
tris(
ti).v[(e + 1) % 3];
104 size_t v =
tris(
ti).v[(e + 2) % 3];
112 if (a.u != b.u)
return a.u < b.u;
113 if (a.v != b.v)
return a.v < b.v;
114 return a.tri < b.tri;
117 for (
size_t i = 0; i + 1 < edges.
size(); ++i)
118 if (edges(i).u == edges(i + 1).u
and edges(i).v == edges(i + 1).v)
120 const size_t t1 = edges(i).tri;
121 const size_t l1 = edges(i).local;
122 const size_t t2 = edges(i + 1).tri;
123 const size_t l2 = edges(i + 1).local;
150 for (
size_t i = 0; i <
tris.size(); ++i)
169 for (
size_t i = 0; i <
tris.size(); ++i)
198 for (
size_t i = 0; i < path.
size() / 2; ++i)
199 std::swap(path(i), path(path.
size() - 1 - i));
214 const Point & source,
215 const Point & target)
220 <<
"Source must be inside the polygon";
222 <<
"Target must be inside the polygon";
225 if (source == target)
230 const Segment seg(source, target);
231 bool blocked =
false;
233 if (
const Segment edge = it.get_current_segment();
270 for (
size_t i = 0; i + 1 <
sleeve.size(); ++i)
272 size_t s0 = 0,
s1 = 0;
276 bool found[3] = {
false,
false,
false};
277 for (
int a = 0; a < 3; ++a)
278 for (
const unsigned long b:
tris(
sleeve(i + 1)).v)
285 for (
int a = 0; a < 3; ++a)
330 const double opacity = -1.0)
347 const bool dashed =
false,
385 const std::string & fill_color =
"gray!25",
386 const double opacity = 0.6)
407 for (
size_t i = 0; i <
pts.size(); ++i)
439 const std::string &
prefix =
"p",
440 const std::string &
placement =
"above right",
444 for (
size_t i = 0; i <
pts.size(); ++i)
446 prefix + std::to_string(i),
463 const std::string &
prefix =
"p",
464 const std::string &
placement =
"above right",
471 prefix + std::to_string(idx),
486 for (
size_t i = 0; i <
polys.size(); ++i)
502 put_in_plane(plane, it.get_current_vertex().to_point(), style, layer);
516 for (
size_t i = 0; i < poly.
size(); ++i)
528 const bool close =
true)
531 for (
size_t i = 0; i < vertices.
size(); ++i)
534 if (close
and poly.
size() >= 3)
552 const bool close =
true)
556 if (
const size_t idx = it.get_curr(); idx < vertices.
size())
559 if (close
and poly.
size() >= 3)
584 template <
typename HullAlgorithm>
641 if (
inter.size() > 0)
699 for (
size_t i = 0; i <
dt.triangles.size(); ++i)
701 const auto & tri =
dt.triangles(i);
744 template <
typename VoronoiResult>
759 for (
size_t i = 0; i <
vor.cells.size(); ++i)
761 const auto & cell =
vor.cells(i);
762 if (
not cell.bounded
or cell.vertices.size() < 3)
769 for (
size_t i = 0; i <
vor.edges.size(); ++i)
770 if (
const auto & e =
vor.edges(i); e.unbounded)
820 for (
size_t i = 0; i <
pd.cells.size(); ++i)
822 const auto & cell =
pd.cells(i);
823 if (cell.vertices.size() < 3)
830 for (
size_t i = 0; i <
pd.edges.size(); ++i)
832 const auto & e =
pd.edges(i);
836 for (
size_t i = 0; i <
pd.sites.size(); ++i)
878 for (
size_t i = 0; i <
arrangement.faces.size(); ++i)
880 const auto & [boundary, unbounded] =
arrangement.faces(i);
886 if (poly.
size() >= 3)
902 for (
size_t i = 0; i <
arrangement.edges.size(); ++i)
956 for (
size_t i = 0; i < snapshot.
partitions.size(); ++i)
994 const auto snapshot =
kd_tree.debug_snapshot();
1028 for (
size_t i = 0; i < snapshot.
nodes.size(); ++i)
1030 const auto & node = snapshot.
nodes(i);
1044 if (query_rect !=
nullptr)
1047 if (query_hits !=
nullptr)
1086 out.query_rect = query_rect;
1107 for (
size_t i = 0; i < snapshot.
nodes.size(); ++i)
1109 const auto & node = snapshot.
nodes(i);
1115 if (query_rect !=
nullptr)
1118 if (query_hit_ids !=
nullptr)
1119 for (
size_t i = 0; i < snapshot.
nodes.size(); ++i)
1120 if (snapshot.
nodes(i).is_leaf)
1121 for (
size_t j = 0; j < query_hit_ids->size(); ++j)
1122 if (snapshot.
nodes(i).user_index == (*query_hit_ids)(j))
1162 out.query_rect = query_rect;
1163 out.query_hit_ids = tree.
query(query_rect);
1165 plane,
out.snapshot, &
out.query_rect, &
out.query_hit_ids,
1185 const Point & curr = it.get_curr();
1207 if (path.
size() == 0)
1210 for (
size_t i = 1; i < path.
size(); ++i)
1227 for (
size_t i = 0; i < portals.
size(); ++i)
1229 const auto & [left, right] = portals(i);
1274 const Point & source,
1275 const Point & target)
1280 if (
trace.portals.size() == 0)
1283 Point apex = source;
1291 committed.
append(source);
1293 for (
size_t i = 1; i <
trace.portals.size(); ++i)
1304 step.right_boundary =
fr;
1305 step.committed_path = committed;
1315 step.tightened_right =
true;
1320 step.emitted_left =
true;
1339 step.tightened_left =
true;
1344 step.emitted_right =
true;
1359 step.right_boundary =
fr;
1360 step.committed_path = committed;
1367 committed.
append(target);
1368 trace.final_path = committed;
1379 const Point & source,
1380 const Point & target,
1402 if (
trace.steps.size() == 0)
1411 if (
step.portal_left !=
step.portal_right)
1416 if (
step.apex !=
step.left_boundary)
1419 if (
step.apex !=
step.right_boundary)
1437 const Point & source,
1438 const Point & target,
1471 const Point & source,
1472 const Point & target,
1514 for (
size_t i = 0; i <
parts.size(); ++i)
1568 for (
size_t n = 0; n <
alpha_shape.triangles.size(); ++n)
1584 for (
size_t i = 0; i <
alpha_shape.boundary_edges.size(); ++i)
1626 for (
size_t i = 0; i <
rt.triangles.size(); ++i)
1628 const auto & tri =
rt.triangles(i);
1630 rt.sites(tri.j).position,
1631 rt.sites(tri.k).position);
1636 for (
size_t i = 0; i <
rt.sites.size(); ++i)
1685 plane, points, result,
1746 for (
size_t i = 0; i <
halfplanes.size(); ++i)
1751 if (intersection.
size() > 0)
1767 return intersection;
1784 if (result.
size() > 0)
1839 const Point & query_point,
1858 const Point & query_point,
1881 for (
size_t i = 0; i < segments.
size(); ++i)
1919 for (
size_t i = 0; i <
cdt.triangles.size(); ++i)
1921 const auto & tri =
cdt.triangles(i);
1926 for (
size_t i = 0; i <
cdt.constrained_edges.size(); ++i)
1928 const auto & e =
cdt.constrained_edges(i);
2101 for (
size_t i = 0; i < result.
polygons.size(); ++i)
2171 const size_t iterations,
2217 for (
size_t i = 0; i <
res.trapezoids.size(); ++i)
2219 const Trap & t =
res.trapezoids(i);
2220 if (! t.active)
continue;
2242 if (x1 == x2)
return (
y1 + y2) / 2;
2243 return y1 + (y2 -
y1) * (x - x1) / (x2 - x1);
2295 for (
size_t i = 0; i <
res.num_input_points; ++i)
2304 for (
size_t j = 0; j <
res.trapezoids.size(); ++j)
2306 const Trap & t =
res.trapezoids(j);
2307 if (! t.active)
continue;
2308 if (t.leftp == NONE
or t.rightp == NONE)
continue;
2321 if (x1 == x2)
return (
y1 + y2) / 2;
2322 return y1 + (y2 -
y1) * (x - x1) / (x2 - x1);
2336 for (
size_t i = 0; i <
res.num_input_segments; ++i)
2355 auto result =
tm(segments);
2374 auto result =
tm(polygon);
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Axis-aligned bounding box tree for spatial queries.
DebugSnapshot debug_snapshot() const
Return the full tree structure for visualization/debug.
Array< size_t > query(const Rectangle &query) const
Find all entries whose bounding box overlaps the query rectangle.
Alpha shape of a point set.
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
void reserve(size_t cap)
Reserves cap cells into the array.
Boolean operations on simple polygons (union, intersection, difference) using the Greiner-Hormann alg...
Op
Type of Boolean operation to perform.
static Polygon smooth_polygon(const Polygon &poly, size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4))
Smooth a closed polygon.
Closest pair of points via divide and conquer.
Constrained Delaunay Triangulation via Sloan's flip-based method.
Decompose a simple polygon into convex parts using Hertel-Mehlhorn.
Basic exact intersection for closed convex polygons.
Polygon triangulation using the ear-cutting algorithm.
Exact Delaunay triangulation using the Bowyer-Watson incremental algorithm.
bool has_curr() const noexcept
Return true if the iterator has current item.
Douglas-Peucker polyline simplification.
Iterator on the items of list.
Dynamic singly linked list with functional programming support.
T & append(const T &item)
bool has_curr() const noexcept
constexpr bool is_empty() const noexcept
Exact bounded intersection of half-planes.
Spatial point index for O(log n) nearest-neighbor queries.
Smallest circle enclosing a point set (Welzl's algorithm).
Exact Minkowski sum of two closed convex polygons.
O(n log n) triangulation of simple polygons via y-monotone partition + linear-time monotone triangula...
static bool contains(const Polygon &poly, const Point &p)
Return true if the point is inside or on the boundary.
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
const Geom_Number & get_y() const noexcept
Gets the y-coordinate value.
Offset (inflate/deflate) an arbitrary simple polygon.
JoinType
Strategy for connecting offset edges at vertices.
@ Miter
Extend edges until they intersect.
Iterator over the edges (segments) of a polygon.
bool has_curr() const
Check if there is a current segment.
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 bool & is_closed() const
Check if the polygon is closed.
const size_t & size() const
Get the number of vertices.
Power diagram (weighted Voronoi diagram).
Static 2D range tree for orthogonal range queries.
DynList< Point > query(const Geom_Number &xmin, const Geom_Number &xmax, const Geom_Number &ymin, const Geom_Number &ymax) const
Query: return all points inside [xmin,xmax] × [ymin,ymax].
DebugSnapshot debug_snapshot() const
Return structural snapshot for visualization/debug.
An axis-aligned rectangle.
const Geom_Number & get_xmin() const
Gets the minimum x-coordinate.
const Geom_Number & get_ymax() const
Gets the maximum y-coordinate.
const Geom_Number & get_ymin() const
Gets the minimum y-coordinate.
const Geom_Number & get_xmax() const
Gets the maximum x-coordinate.
Exact regular triangulation (weighted Delaunay) via Bowyer-Watson.
A regular polygon defined by center, side length, and vertex count.
Point get_vertex(const size_t &i) const
Get the i-th vertex of the polygon.
const size_t & size() const
Get the number of vertices.
static DiameterResult diameter(const Polygon &poly)
Compute convex polygon diameter (farthest vertex pair).
static WidthResult minimum_width(const Polygon &poly)
Compute the minimum width of a closed convex polygon.
Compute the full planar subdivision induced by a set of segments.
Represents a line segment between two points.
bool intersects_properly_with(const Segment &s) const
Checks if this segment properly intersects another segment.
const Point & get_tgt_point() const noexcept
Gets the target point of the segment.
const Point & get_src_point() const noexcept
Gets the source point of the segment.
Compute the shortest Euclidean path between two points inside a simple polygon.
Report all pairwise intersection points among a set of segments.
2D TikZ canvas storing geometry objects and emitting LaTeX output.
static constexpr int Layer_Default
static constexpr int Layer_Foreground
static constexpr int Layer_Background
static constexpr int Layer_Overlay
O(log n) point location via trapezoidal map with DAG search.
static constexpr size_t NONE
A non-degenerate triangle defined by three points.
const Point & get_p3() const
Gets the third vertex.
const Point & get_p2() const
Gets the second vertex.
const Point & get_p1() const
Gets the first vertex.
Compute the visibility polygon from a point inside a simple polygon.
Visvalingam-Whyatt polyline simplification.
O(n log n) Voronoi diagram construction.
Computational geometry algorithms.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y1_function > > y1(const __gmp_expr< T, U > &expr)
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_y0_function > > y0(const __gmp_expr< T, U > &expr)
bool spp_point_in_triangle(const Array< Point > &pts, const SPP_ITri &t, const Point &p)
size_t spp_find_tri(const Array< Point > &pts, const Array< SPP_ITri > &tris, const Point &p)
constexpr size_t SPP_NONE
size_t spp_find_index(const Array< Point > &pts, const Point &p)
Array< size_t > spp_find_sleeve(const Array< SPP_ITri > &tris, const size_t src, const size_t dst)
std::string tikz_palette_color(const size_t idx)
Geom_Number spp_cross(const Point &a, const Point &b, const Point &c)
Array< SPP_Portal > shortest_path_portals(const Polygon &polygon, const Point &source, const Point &target)
Array< SPP_ITri > spp_build_tris(const Array< Point > &pts, const DynList< Triangle > &tl)
Main namespace for Aleph-w library functions.
void put_convex_decomposition_result(Tikz_Plane &plane, const Array< Polygon > &parts, const bool color_parts_by_index=true, const Tikz_Style &part_style=tikz_area_style("blue!60!black", "blue!15", 0.40), const int part_layer=Tikz_Plane::Layer_Default)
Insert convex decomposition polygons.
and
Check uniqueness with explicit hash + equality functors.
void put_half_plane_intersection_result(Tikz_Plane &plane, const Array< HalfPlaneIntersection::HalfPlane > &halfplanes, const Polygon &intersection, 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), const int boundary_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Draw half-plane boundaries and their bounded intersection polygon.
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.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
Polygon visualize_visvalingam_whyatt(Tikz_Plane &plane, const Polygon &poly, const Geom_Number &area_threshold, const VisvalingamWhyattSimplification &algorithm={}, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &simplified_style=tikz_wire_style("green!70!black", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Simplify a polygon with Visvalingam-Whyatt and draw the result.
void put_range_tree_result(Tikz_Plane &plane, const RangeTree2D::DebugSnapshot &snapshot, const bool draw_points=true, const Rectangle *query_rect=nullptr, const DynList< Point > *query_hits=nullptr, 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"), const int split_layer=Tikz_Plane::Layer_Default, const int point_layer=Tikz_Plane::Layer_Foreground)
Draw range-tree X-axis hierarchy and optional query highlights.
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.
Orientation
Classification of three-point orientation.
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.
void put_visibility_polygon_result(Tikz_Plane &plane, const Polygon &polygon, const Point &query_point, const Polygon &visibility_polygon, 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"), const int polygon_layer=Tikz_Plane::Layer_Default, const int visibility_layer=Tikz_Plane::Layer_Foreground)
Draw visibility polygon with source polygon and query point.
void put_rotating_calipers_result(Tikz_Plane &plane, const Polygon &polygon, const RotatingCalipersResult &result, 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"), const int polygon_layer=Tikz_Plane::Layer_Default, const int witness_layer=Tikz_Plane::Layer_Foreground)
Draw diameter and minimum-width witnesses for a convex polygon.
void put_cdt_result(Tikz_Plane &plane, const ConstrainedDelaunayTriangulation::Result &cdt, const Tikz_Style &triangle_style=tikz_wire_style("blue!60"), const Tikz_Style &constraint_style=tikz_path_style("red"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"), const int triangle_layer=Tikz_Plane::Layer_Default, const int constraint_layer=Tikz_Plane::Layer_Foreground, const int site_layer=Tikz_Plane::Layer_Overlay)
Insert constrained Delaunay triangulation result.
AABBTree::DebugSnapshot visualize_aabb_tree(Tikz_Plane &plane, const AABBTree &tree, const Tikz_Style &node_bbox_style=tikz_wire_style("teal!70!black"), const Tikz_Style &leaf_bbox_style=tikz_wire_style("blue!70"))
Visualize AABB tree hierarchy.
void put_offset_result(Tikz_Plane &plane, const Polygon &original, const PolygonOffset::Result &result, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &offset_style=tikz_wire_style("blue!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Draw a polygon offset result overlaid on the original polygon.
MinimumEnclosingCircle::Circle visualize_mec(Tikz_Plane &plane, const DynList< Point > &points, const MinimumEnclosingCircle &algorithm={}, const Tikz_Style &circle_style=tikz_wire_style("blue!70"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute minimum enclosing circle and insert into 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.
void put_alpha_shape_result(Tikz_Plane &plane, const AlphaShape::Result &alpha_shape, 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"), const int triangle_layer=Tikz_Plane::Layer_Background, const int boundary_layer=Tikz_Plane::Layer_Foreground, const int site_layer=Tikz_Plane::Layer_Overlay)
Insert alpha-shape structures (kept triangles, boundary, 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.
RangeTree2D::DebugSnapshot visualize_range_tree(Tikz_Plane &plane, const RangeTree2D &tree, const bool draw_points=true, const Tikz_Style &split_style=tikz_wire_style("purple"), const Tikz_Style &point_style=tikz_points_style("black"))
Visualize range-tree structure without a query overlay.
void put_monotone_triangulation_result(Tikz_Plane &plane, const Polygon &polygon, const DynList< Triangle > &triangles, const Tikz_Style &polygon_style=tikz_wire_style("black"), const Tikz_Style &triangle_style=tikz_wire_style("blue!65"), const int polygon_layer=Tikz_Plane::Layer_Default, const int triangle_layer=Tikz_Plane::Layer_Foreground)
Draw a monotone triangulation result plus polygon boundary.
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.
TrapezoidalMapPointLocation::Result visualize_trapezoidal_map(Tikz_Plane &plane, const Array< Segment > &segments, const Tikz_Style &segment_style=tikz_path_style("red"), const Tikz_Style &extension_style=tikz_wire_style("gray!60", true), const bool draw_trapezoids=true, const double trapezoid_opacity=0.3)
Build a trapezoidal map and draw it.
Polygon polygon_from_vertex_indices(const Array< Point > &vertices, const DynList< size_t > &indices, const bool close=true)
Constructs a Polygon from a list of indices into a vertex array.
void put_smoothing_result(Tikz_Plane &plane, const Polygon &original, const Polygon &smoothed, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &smoothed_style=tikz_wire_style("violet!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Draw original and smoothed polygons overlaid.
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.
void put_mec_result(Tikz_Plane &plane, const MinimumEnclosingCircle::Circle &circle, const DynList< Point > &points, const Tikz_Style &circle_style=tikz_wire_style("blue!70"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"), const int circle_layer=Tikz_Plane::Layer_Default, const int site_layer=Tikz_Plane::Layer_Overlay)
Draw a precomputed minimum enclosing circle result.
Polygon polygon_from_vertices(const Array< Point > &vertices, const bool close=true)
Constructs a Polygon from an ordered array of vertices.
void put_minkowski_sum_result(Tikz_Plane &plane, const Polygon &first, const Polygon &second, const Polygon &result, 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), const int input_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Draw input polygons and their Minkowski sum result.
void put_closest_pair_result(Tikz_Plane &plane, const DynList< Point > &points, const ClosestPairDivideAndConquer::Result &result, 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"), const int points_layer=Tikz_Plane::Layer_Default, const int pair_layer=Tikz_Plane::Layer_Foreground)
Draw closest-pair result over the full point set.
void put_segment_arrangement_result(Tikz_Plane &plane, const SegmentArrangement::Result &arrangement, 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 int face_layer=Tikz_Plane::Layer_Background, const int edge_layer=Tikz_Plane::Layer_Default, const int vertex_layer=Tikz_Plane::Layer_Foreground, const bool color_faces_by_index=false)
Insert segment arrangement structures (faces, edges, vertices).
void put_kdtree_partitions_result(Tikz_Plane &plane, const KDTreePointSearch::DebugSnapshot &snapshot, 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"), const int partition_layer=Tikz_Plane::Layer_Background, const int split_layer=Tikz_Plane::Layer_Default, const int point_layer=Tikz_Plane::Layer_Foreground)
Draw KD-tree partitions from a debug snapshot.
Geom_Number square_root(const Geom_Number &x)
Square root of x (wrapper over mpfr).
static void prefix(Node *root, DynList< Node * > &acc)
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.
void put_polygon_vertices(Tikz_Plane &plane, const Polygon &poly, const Tikz_Style &style=tikz_points_style(), const int layer=Tikz_Plane::Layer_Overlay)
Inserts the vertices of a polygon as styled points.
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.
void put_regular_triangulation_result(Tikz_Plane &plane, const RegularTriangulationBowyerWatson::Result &rt, const Tikz_Style &triangle_style=tikz_wire_style("blue!60"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"), const int triangle_layer=Tikz_Plane::Layer_Default, const int site_layer=Tikz_Plane::Layer_Foreground)
Draw regular (weighted Delaunay) triangulation output.
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.
Tikz_Style tikz_path_style(const std::string &color="red", const bool with_arrow=false)
Creates a style optimized for polyline paths.
void put_points(Tikz_Plane &plane, const Array< Point > &pts, const Tikz_Style &style=tikz_points_style(), const int layer=Tikz_Plane::Layer_Default)
Inserts all points from an Array<Point> into the plane.
void put_power_diagram_result(Tikz_Plane &plane, const PowerDiagram::Result &pd, 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"), const int cell_layer=Tikz_Plane::Layer_Background, const int edge_layer=Tikz_Plane::Layer_Default, const int site_layer=Tikz_Plane::Layer_Foreground)
Insert Power diagram structures (cells, edges, weighted sites).
Orientation orientation(const Point &a, const Point &b, const Point &c)
Return the orientation of the triple (a, b, c).
void put_polygons(Tikz_Plane &plane, const Array< Polygon > &polys, const Tikz_Style &style=tikz_wire_style(), const int layer=Tikz_Plane::Layer_Default)
Inserts all polygons from an Array<Polygon> into the plane.
void put_voronoi_result(Tikz_Plane &plane, const VoronoiResult &vor, 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), const int cell_layer=Tikz_Plane::Layer_Background, const int edge_layer=Tikz_Plane::Layer_Default, const int site_layer=Tikz_Plane::Layer_Foreground)
Insert Voronoi diagram structures (cells, edges, sites).
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 put_point_label_in_plane(Tikz_Plane &plane, const Point &point, const std::string &label, const std::string &placement="above", const Tikz_Style &style=make_tikz_draw_style("black"), const int layer=Tikz_Plane::Layer_Overlay)
Insert a point label with configurable placement (above, etc.).
PolygonOffset::Result visualize_polygon_offset(Tikz_Plane &plane, const Polygon &poly, const Geom_Number &distance, const PolygonOffset &algorithm={}, PolygonOffset::JoinType join=PolygonOffset::JoinType::Miter, const Geom_Number &miter_limit=Geom_Number(2), const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &offset_style=tikz_wire_style("blue!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Offset a polygon and draw the result.
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.
void put_point_labels(Tikz_Plane &plane, const Array< Point > &pts, const std::string &prefix="p", const std::string &placement="above right", const Tikz_Style &style=make_tikz_draw_style("black"), const int layer=Tikz_Plane::Layer_Overlay)
Adds a text label to each point in an Array<Point>.
void put_line_sweep_result(Tikz_Plane &plane, const Array< Segment > &segments, const Array< SweepLineSegmentIntersection::Intersection > &intersections, const Tikz_Style &segment_style=tikz_wire_style("blue!60"), const Tikz_Style &intersection_style=tikz_points_style("red"), const int segment_layer=Tikz_Plane::Layer_Default, const int intersection_layer=Tikz_Plane::Layer_Foreground)
Draw line segments and all sweep-line intersection points.
Polygon visualize_douglas_peucker(Tikz_Plane &plane, const Polygon &poly, const Geom_Number &epsilon, const DouglasPeuckerSimplification &algorithm={}, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &simplified_style=tikz_wire_style("blue!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Simplify a polygon with Douglas-Peucker and draw the result.
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 make_tikz_draw_style(const std::string &draw_color)
Create a basic draw style with a custom color.
void put_aabb_tree_result(Tikz_Plane &plane, const AABBTree::DebugSnapshot &snapshot, const Rectangle *query_rect=nullptr, const Array< size_t > *query_hit_ids=nullptr, 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"), const int node_layer=Tikz_Plane::Layer_Default, const int query_layer=Tikz_Plane::Layer_Foreground)
Draw AABB tree hierarchy and optional query results.
std::ostream & join(const C &c, const std::string &sep, std::ostream &out)
Join elements of an Aleph-style container into a stream.
Point ray_endpoint(const Point &src, const Point &direction, const Geom_Number &length)
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.
void put_trapezoidal_map_result(Tikz_Plane &plane, const TrapezoidalMapPointLocation::Result &res, const Tikz_Style &segment_style=tikz_path_style("red"), const Tikz_Style &extension_style=tikz_wire_style("gray!60", true), const bool draw_trapezoids=true, const double trapezoid_opacity=0.3, const int trap_layer=Tikz_Plane::Layer_Background, const int seg_layer=Tikz_Plane::Layer_Foreground, const int ext_layer=Tikz_Plane::Layer_Default)
Draw the trapezoidal map result into a Tikz_Plane.
ConstrainedDelaunayTriangulation::Result visualize_cdt(Tikz_Plane &plane, const DynList< Point > &points, const DynList< Segment > &constraints, const ConstrainedDelaunayTriangulation &algorithm={}, const Tikz_Style &triangle_style=tikz_wire_style("blue!60"), const Tikz_Style &constraint_style=tikz_path_style("red"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"))
Compute and insert constrained Delaunay triangulation.
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.
void put_simplification_result(Tikz_Plane &plane, const Polygon &original, const Polygon &simplified, const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &simplified_style=tikz_wire_style("blue!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Draw original and simplified polygons overlaid.
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.
Array< Polygon > visualize_boolean_operation(Tikz_Plane &plane, const Polygon &a, const Polygon &b, const BooleanPolygonOperations::Op op, const BooleanPolygonOperations &bop={}, const Tikz_Style &a_style=tikz_area_style("blue", "blue!15", 0.35), const Tikz_Style &b_style=tikz_area_style("green!60!black", "green!20", 0.35), const Tikz_Style &result_style=tikz_area_style("red", "red!35", 0.65), const int input_layer=Tikz_Plane::Layer_Default, const int result_layer=Tikz_Plane::Layer_Foreground)
Visualizes a boolean operation (union, intersection, difference) on two 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).
void put_portals(Tikz_Plane &plane, const Array< FunnelPortal > &portals, const bool skip_degenerate=true, const Tikz_Style &portal_style=tikz_wire_style("purple", true), const int portal_layer=Tikz_Plane::Layer_Default)
Insert funnel portals as segment connectors.
Polygon visualize_chaikin_smoothing(Tikz_Plane &plane, const Polygon &poly, const size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4), const Tikz_Style &original_style=tikz_wire_style("gray!50"), const Tikz_Style &smoothed_style=tikz_wire_style("violet!80", 1.2), const bool draw_vertices=true, const Tikz_Style &vertex_style=tikz_points_style("red"))
Smooth a polygon with Chaikin subdivision and draw the result.
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.
void put_delaunay_result(Tikz_Plane &plane, const DelaunayTriangulationBowyerWatson::Result &dt, const Tikz_Style &triangle_style=tikz_wire_style("blue"), const bool draw_sites=true, const Tikz_Style &site_style=tikz_points_style("black"), const int triangle_layer=Tikz_Plane::Layer_Default, const int site_layer=Tikz_Plane::Layer_Foreground)
Insert Delaunay triangulation as triangle outlines.
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.
void put_path(Tikz_Plane &plane, const DynList< Point > &path, const Tikz_Style &segment_style=tikz_path_style("red"), const bool draw_waypoints=true, const Tikz_Style &waypoint_style=tikz_points_style("red"), const int segment_layer=Tikz_Plane::Layer_Foreground, const int waypoint_layer=Tikz_Plane::Layer_Overlay)
Insert a point path as connected segments and optional waypoints.
static long & color(typename GT::Node *p)
void quicksort_op(C< T > &a, const Compare &cmp=Compare(), const size_t threshold=Quicksort_Threshold)
Optimized quicksort for containers using operator().
Result bundle for AABB query visualization.
AABBTree::DebugSnapshot snapshot
Array< size_t > query_hit_ids
A snapshot of the entire tree for debugging.
Array< DebugNode > nodes
Array of all nodes in debug format.
Result of an alpha-shape computation.
The result of a Delaunay triangulation.
Full trace for shortest-path funnel processing.
Array< FunnelPortal > portals
Array< FunnelTraceStep > steps
Array< Point > final_path
One SSFA (funnel) iteration snapshot.
Array< Point > committed_path
A complete snapshot of the tree for debugging.
Array< DebugPartition > partitions
List of all internal and leaf partitions.
Array< Point > points
All points stored in the tree.
Result type: a circle defined by center and squared radius.
Geom_Number radius() const
Exact radius (square root of radius_squared).
The result of an offset operation, which may produce multiple polygons.
Array< Polygon > polygons
Set of resulting simple polygons.
Iterator over the vertices of a polygon.
Complete result of a power diagram computation.
A complete snapshot of the range tree for debugging.
Array< DebugNode > nodes
List of all nodes in debug format.
Array< Point > x_sorted_points
The underlying x-sorted point array.
Result bundle for range-tree query visualization.
RangeTree2D::DebugSnapshot snapshot
DynList< Point > query_hits
Bundle of rotating-calipers results used by visualization helpers.
RotatingCalipersConvexPolygon::WidthResult width
RotatingCalipersConvexPolygon::DiameterResult diameter
The complete result of the segment arrangement computation.
Result bundle for shortest-path + funnel portal visualization.
Array< FunnelPortal > portals
Style descriptor for TikZ primitives.
std::string fill_color
TikZ fill color (fill=<color>)
double opacity
opacity=<value> in [0,1], when >= 0
bool fill
Fill closed shapes (polygon/triangle/ellipse)
std::string draw_color
TikZ draw color (draw=<color>)
The trapezoidal map and DAG search structure.
A trapezoid in the decomposition.
The complete result of a Voronoi diagram computation.
TikZ/LaTeX geometric drawing utilities.