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); } } } diff --git a/Polygon_repair/include/CGAL/Polygon_repair/repair.h b/Polygon_repair/include/CGAL/Polygon_repair/repair.h index 03961636059..d60519226b8 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) { @@ -93,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()) { @@ -107,6 +119,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) { @@ -791,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) @@ -816,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 @@ -848,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) @@ -880,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 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; +} +