48 case LT::TRAPEZOID:
return "TRAPEZOID";
49 case LT::ON_SEGMENT:
return "ON_SEGMENT";
50 case LT::ON_POINT:
return "ON_POINT";
72 cout <<
"=== Trapezoidal Map Point Location Example ===\n\n";
73 cout <<
"L-shaped polygon with 6 vertices, 6 edges.\n\n";
81 for (
size_t i = 0; i < result.trapezoids.size(); ++i)
82 if (result.trapezoids(i).active) ++active;
83 cout <<
"Trapezoidal map: " << active <<
" active trapezoids, "
84 << result.dag.size() <<
" DAG nodes.\n\n";
95 {
Point(1, 1),
"inside (lower part)"},
96 {
Point(1, 3),
"inside (upper part)"},
97 {
Point(3, 1),
"inside (right part)"},
98 {
Point(3, 3),
"outside (reflex area)"},
99 {
Point(5, 1),
"outside (far right)"},
100 {
Point(0, 0),
"vertex"},
101 {
Point(2, 0),
"edge midpoint"},
102 {
Point(2, 2),
"reflex vertex"},
105 cout <<
"Point queries:\n";
108 auto loc = result.locate(q.p);
109 bool inside = result.contains(q.p);
110 cout <<
" (" << q.p.
get_x() <<
", " << q.p.get_y() <<
") "
112 << (
inside ?
" [INSIDE]" :
" [OUTSIDE]") <<
"\n";
116 const char *
tex_file =
"trapezoidal_map_example_output.tex";
117 cout <<
"\nWriting TikZ output to " <<
tex_file <<
" ...\n";
125 bool inside = result.contains(q.p);
126 auto loc = result.locate(q.p);
127 std::string
color =
"red";
128 if (loc.type == LT::ON_SEGMENT
or loc.type == LT::ON_POINT)
131 color =
"green!70!black";
141 cout <<
"Done. Compile with: pdflatex " <<
tex_file <<
"\n";
Represents a point with rectangular coordinates in a 2D plane.
const Geom_Number & get_x() const noexcept
Gets the x-coordinate value.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the 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_Overlay
O(log n) point location via trapezoidal map with DAG search.
LocationType
Classification of a point location query result.
Main namespace for Aleph-w library functions.
void put_in_plane(Tikz_Plane &plane, const Geom &geom_obj)
Insert any supported geometry type in a Tikz_Plane.
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_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.
Tikz_Style tikz_points_style(const std::string &color="black", const double opacity=-1.0)
Creates a style optimized for point clouds.
static long & color(typename GT::Node *p)
Style descriptor for TikZ primitives.
Helpers to visualize computational-geometry algorithm results in TikZ.
static const char * location_name(LT t)