From 569d3e5e55138af0be84698498730822b357004c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 10 Jun 2025 10:40:19 +0100 Subject: [PATCH 1/3] Polygon_repair: Add overloads for Non_zero_rule --- .../include/CGAL/Polygon_repair/repair.h | 22 +++++++++++ .../test/Polygon_repair/CMakeLists.txt | 1 + .../repair_polygon_non_zero_2_test.cpp | 37 +++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 Polygon_repair/test/Polygon_repair/repair_polygon_non_zero_2_test.cpp diff --git a/Polygon_repair/include/CGAL/Polygon_repair/repair.h b/Polygon_repair/include/CGAL/Polygon_repair/repair.h index 03961636059..871bf75ff71 100644 --- a/Polygon_repair/include/CGAL/Polygon_repair/repair.h +++ b/Polygon_repair/include/CGAL/Polygon_repair/repair.h @@ -77,6 +77,17 @@ Multipolygon_with_holes_2 repair(const Polygon_with_holes_2 +Multipolygon_with_holes_2 repair(const Polygon_2& p, Non_zero_rule) +{ + Winding winding; + winding.insert(p); + winding.label(); + winding.label_domains(); + return winding(); +} + + template Multipolygon_with_holes_2 repair(const Polygon_with_holes_2& p, Non_zero_rule) { @@ -107,6 +118,17 @@ Multipolygon_with_holes_2 repair(const Multipolygon_with_hole } +template +Multipolygon_with_holes_2 repair(const Multipolygon_with_holes_2& p, Non_zero_rule) +{ + Winding winding; + winding.insert(p); + winding.label(); + winding.label_domains(); + return winding(); +} + + template Multipolygon_with_holes_2 repair(const Multipolygon_with_holes_2& p, Union_rule) { diff --git a/Polygon_repair/test/Polygon_repair/CMakeLists.txt b/Polygon_repair/test/Polygon_repair/CMakeLists.txt index 1ec7a341fc2..d0424660631 100644 --- a/Polygon_repair/test/Polygon_repair/CMakeLists.txt +++ b/Polygon_repair/test/Polygon_repair/CMakeLists.txt @@ -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) diff --git a/Polygon_repair/test/Polygon_repair/repair_polygon_non_zero_2_test.cpp b/Polygon_repair/test/Polygon_repair/repair_polygon_non_zero_2_test.cpp new file mode 100644 index 00000000000..d289d95e735 --- /dev/null +++ b/Polygon_repair/test/Polygon_repair/repair_polygon_non_zero_2_test.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +#include +#include +#include +#include + +using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel; +using Point_2 = Kernel::Point_2; +using Polygon_2 = CGAL::Polygon_2; +using Polygon_with_holes_2 = CGAL::Polygon_with_holes_2; +using Multipolygon_with_holes_2 = CGAL::Multipolygon_with_holes_2; +using Polygon_repair = CGAL::Polygon_repair::Polygon_repair; + +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; +} + From aef9a07d2a63eca3d2d3fd0587bed8f2696bb006 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 10 Jun 2025 14:37:06 +0100 Subject: [PATCH 2/3] Add that for join() and intersect() the input must have correct orientation --- Polygon_repair/include/CGAL/Polygon_repair/repair.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Polygon_repair/include/CGAL/Polygon_repair/repair.h b/Polygon_repair/include/CGAL/Polygon_repair/repair.h index 871bf75ff71..d60519226b8 100644 --- a/Polygon_repair/include/CGAL/Polygon_repair/repair.h +++ b/Polygon_repair/include/CGAL/Polygon_repair/repair.h @@ -104,7 +104,8 @@ Multipolygon_with_holes_2 repair(const Polygon_with_holes_2 Multipolygon_with_holes_2 repair(const Multipolygon_with_holes_2& p, Rule = Rule()) { @@ -813,7 +814,8 @@ protected: /// computes the union of all polygons with holes in `p` /// \tparam Kernel parameter of the input and output polygons. Must be model of `ConstrainedDelaunayTriangulationTraits_2 ` /// \tparam Container parameter of the input and output polygons -/// \pre Each polygon with hole must be free of self-intersections +/// \pre Each polygon with holes must be free of self-intersections, +/// the outer boundaries must be counterclockwise and the holes clockwise oriented. template Multipolygon_with_holes_2 join(const Multipolygon_with_holes_2& pa) @@ -838,7 +840,8 @@ join(const Multipolygon_with_holes_2& pa) /// \tparam Container parameter of the input and output polygons /// \tparam PA must be `Polygon_2`, or `Polygon_with_holes_2`, or `Multipolygon_with_holes_2` /// \tparam PB must be `Polygon_2`, or `Polygon_with_holes_2`, or `Multipolygon_with_holes_2` -/// \pre The polygons `pa` and `pb` must be free of self-intersections +/// \pre The polygons `pa` and `pb` must be free of self-intersections, +/// the outer boundaries must be counterclockwise and the holes clockwise oriented. template #ifdef DOXYGEN_RUNNING Multipolygon_with_holes_2 @@ -870,7 +873,8 @@ join(const PA& pa, const PB& pb, const Kernel& = Default(), const Container& = D /// computes the intersection of all polygons with holes in `p` /// \tparam Kernel parameter of the input and output polygons. Must be model of `ConstrainedDelaunayTriangulationTraits_2 ` /// \tparam Container parameter of the input and output polygons -/// \pre Each polygon with hole must be free of self-intersections +/// \pre Each polygon with holes must be free of self-intersections +/// the outer boundaries must be counterclockwise and the holes clockwise oriented. template Multipolygon_with_holes_2 intersect(const Multipolygon_with_holes_2& p) @@ -902,6 +906,7 @@ intersect(const Multipolygon_with_holes_2& p) /// \tparam PA must be `Polygon_2`, or `Polygon_with_holes_2`, or `Multipolygon_with_holes_2` /// \tparam PB must be `Polygon_2`, or `Polygon_with_holes_2`, or `Multipolygon_with_holes_2` /// \pre The polygons `pa` and `pb` must be free of self-intersections +/// the outer boundaries must be counterclockwise and the holes clockwise oriented. template #ifdef DOXYGEN_RUNNING Multipolygon_with_holes_2 From f69042067cb48676b3b6d2be47cc1ab9e9d895aa Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 11 Jun 2025 08:34:19 +0100 Subject: [PATCH 3/3] remove unused local variables --- Polygon_repair/include/CGAL/Polygon_repair/Winding.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Polygon_repair/include/CGAL/Polygon_repair/Winding.h b/Polygon_repair/include/CGAL/Polygon_repair/Winding.h index c40865c67e7..afb2ee2ea05 100644 --- a/Polygon_repair/include/CGAL/Polygon_repair/Winding.h +++ b/Polygon_repair/include/CGAL/Polygon_repair/Winding.h @@ -135,7 +135,7 @@ sets the polygon as input of the winding number computation. void insert(const Polygon_2& p) { - Constraint_id cidA = cdt.insert_constraint(p.vertices_begin(), p.vertices_end(), true); + cdt.insert_constraint(p.vertices_begin(), p.vertices_end(), true); } /*! @@ -144,9 +144,9 @@ sets the polygon as input of the winding number computation. void insert(const Polygon_with_holes_2& pwh) { - Constraint_id cidA = cdt.insert_constraint(pwh.outer_boundary().vertices_begin(), pwh.outer_boundary().vertices_end(), true); + cdt.insert_constraint(pwh.outer_boundary().vertices_begin(), pwh.outer_boundary().vertices_end(), true); for(auto const& hole : pwh.holes()){ - cidA = cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true); + cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true); } } @@ -157,9 +157,9 @@ sets the polygon as input of the winding number computation. insert(const Multipolygon_with_holes_2& mpwh) { for(const auto& pwh : mpwh.polygons_with_holes()){ - Constraint_id cidA = cdt.insert_constraint(pwh.outer_boundary().vertices_begin(), pwh.outer_boundary().vertices_end(), true); + cdt.insert_constraint(pwh.outer_boundary().vertices_begin(), pwh.outer_boundary().vertices_end(), true); for(auto const& hole : pwh.holes()){ - cidA = cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true); + cdt.insert_constraint(hole.vertices_begin(), hole.vertices_end(), true); } } }