Polygon_repair: Add overloads for Non_zero_rule

This commit is contained in:
Andreas Fabri 2025-06-10 10:40:19 +01:00
parent 0fb70f5cd5
commit 569d3e5e55
3 changed files with 60 additions and 0 deletions

View File

@ -77,6 +77,17 @@ Multipolygon_with_holes_2<Kernel, Container> repair(const Polygon_with_holes_2<K
}
template <class Kernel, class Container>
Multipolygon_with_holes_2<Kernel, Container> repair(const Polygon_2<Kernel, Container>& p, Non_zero_rule)
{
Winding<Kernel> winding;
winding.insert(p);
winding.label();
winding.label_domains();
return winding();
}
template <class Kernel, class Container>
Multipolygon_with_holes_2<Kernel, Container> repair(const Polygon_with_holes_2<Kernel, Container>& p, Non_zero_rule)
{
@ -107,6 +118,17 @@ Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_hole
}
template <class Kernel, class Container>
Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_holes_2<Kernel, Container>& p, Non_zero_rule)
{
Winding<Kernel> winding;
winding.insert(p);
winding.label();
winding.label_domains();
return winding();
}
template <class Kernel, class Container>
Multipolygon_with_holes_2<Kernel, Container> repair(const Multipolygon_with_holes_2<Kernel, Container>& p, Union_rule)
{

View File

@ -18,6 +18,7 @@ find_package(CGAL REQUIRED OPTIONAL_COMPONENTS Qt6)
create_single_source_cgal_program( "draw_test_polygons.cpp" )
create_single_source_cgal_program( "exact_test.cpp")
create_single_source_cgal_program( "repair_polygon_2_test.cpp" )
create_single_source_cgal_program( "repair_polygon_non_zero_2_test.cpp" )
if(CGAL_Qt6_FOUND)
target_link_libraries(draw_test_polygons PRIVATE CGAL::CGAL_Basic_viewer)

View File

@ -0,0 +1,37 @@
#include <CGAL/Polygon_repair/repair.h>
#include <CGAL/IO/WKT.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_2 = Kernel::Point_2;
using Polygon_2 = CGAL::Polygon_2<Kernel>;
using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2<Kernel>;
using Multipolygon_with_holes_2 = CGAL::Multipolygon_with_holes_2<Kernel>;
using Polygon_repair = CGAL::Polygon_repair::Polygon_repair<Kernel>;
int main() {
std::string polygon("POLYGON((0 0, 3 0, 3 3, 4 3,0 0))");
std::istringstream in(polygon);
Polygon_with_holes_2 pwh;
CGAL::IO::read_polygon_WKT(in, pwh);
Polygon_2 outer = pwh.outer_boundary();
Multipolygon_with_holes_2 rmp;
rmp = CGAL::Polygon_repair::repair(outer, CGAL::Polygon_repair::Non_zero_rule());
rmp = CGAL::Polygon_repair::repair(pwh, CGAL::Polygon_repair::Non_zero_rule());
rmp = CGAL::Polygon_repair::repair(rmp, CGAL::Polygon_repair::Non_zero_rule());
std::cout << "done" << std::endl;
return 0;
}