64 const Point & p = it.get_current_vertex();
93 out <<
"site_index,site_x,site_y,vertex_count,wkt\n";
95 for (
size_t i = 0; i < cells.
size(); ++i)
97 const auto & c = cells(i);
98 out << c.site_index <<
","
101 << c.polygon.size() <<
",\"";
108int main(
int argc,
char ** argv)
114 Point(0, 0),
Point(6, 0),
Point(8, 4),
Point(5, 8),
Point(1, 7),
121 clip.add_vertex(
Point(10, -2));
122 clip.add_vertex(
Point(10, 10));
123 clip.add_vertex(
Point(-2, 10));
129 cout << fixed << setprecision(4);
130 cout <<
"Voronoi clipped cells (site-indexed)\n";
131 cout <<
"===================================\n";
132 cout <<
"Sites: " << vor.sites.size() <<
"\n";
133 cout <<
"Cells: " << cells.
size() <<
"\n\n";
135 assert(cells.
size() == vor.sites.size());
138 for (
size_t i = 0; i < cells.
size(); ++i)
140 const auto & c = cells(i);
141 cout <<
"Cell #" << c.site_index
144 <<
" vertices=" << c.polygon.size() <<
"\n";
146 assert(c.polygon.is_closed());
147 assert(c.polygon.size() >= 3);
148 assert(pip.
contains(c.polygon, c.site));
151 const char * path = (argc > 1) ? argv[1] :
"voronoi_clipped_cells_output.csv";
155 cerr <<
"Cannot open output file: " << path <<
"\n";
159 file << fixed << setprecision(8);
163 cout <<
"\nCSV/WKT exported to: " << path <<
"\n";
164 cout <<
"Format: site_index, site_x, site_y, vertex_count, WKT polygon\n";
size_t size_t int32_t * out
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
bool has_curr() const noexcept
Return true if the iterator has current item.
Exact point-in-polygon classification via winding number.
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.
A general (irregular) 2D polygon defined by a sequence of vertices.
void add_vertex(const Point &point)
Add a vertex to the polygon.
Voronoi diagram derived as the dual of a Delaunay triangulation.
static Array< ClippedCell > clipped_cells_indexed(const Array< Point > &sites, const Polygon &clip)
Clip Voronoi cells and return explicit site-indexed records.
Computational geometry algorithms.
Main namespace for Aleph-w library functions.
double geom_number_to_double(const Geom_Number &n)
Converts a Geom_Number to its double precision representation.
Iterator over the vertices of a polygon.
static void export_cells_csv(ostream &out, const Array< VoronoiDiagramFromDelaunay::ClippedCell > &cells)
static void write_polygon_wkt(ostream &out, const Polygon &poly)