From 4117fcd727f6d10d65a4daecf1974262e73a2028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 13 Jun 2019 09:31:02 +0200 Subject: [PATCH 1/2] allocate new outer ccb if the initial set is empty --- .../Gps_on_surface_base_2.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_on_surface_base_2.h b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_on_surface_base_2.h index 4d28d31d31d..f0c586f0397 100644 --- a/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_on_surface_base_2.h +++ b/Boolean_set_operations_2/include/CGAL/Boolean_set_operations_2/Gps_on_surface_base_2.h @@ -1212,6 +1212,7 @@ protected: for (Halfedge_iterator itr = arr->halfedges_begin(); itr != arr->halfedges_end(); ++itr) { Halfedge_handle h = itr; + CGAL_assertion(h->face() != Face_handle()); if (h->face()->id_not_set()) continue; CGAL_assertion(h->flag()!=NOT_VISITED); @@ -1250,10 +1251,17 @@ protected: inner_ccb_and_new_face_pairs.push_back( std::make_pair(inner_ccb, f) ); } else{ - // we never create more outer ccb than what was available - CGAL_assertion(!outer_ccbs_to_remove.empty()); - typename Aos_2::Dcel::Outer_ccb* outer_ccb = outer_ccbs_to_remove.back(); - outer_ccbs_to_remove.pop_back(); + // create a new outer ccb if none is available + typename Aos_2::Dcel::Outer_ccb* outer_ccb; + if (!outer_ccbs_to_remove.empty()) + { + outer_ccb = outer_ccbs_to_remove.back(); + outer_ccbs_to_remove.pop_back(); + } + else{ + outer_ccb = accessor.new_outer_ccb(); + outer_ccb->set_face(f); + } Halfedge_handle hstart=h; do{ _halfedge(h)->set_outer_ccb(outer_ccb); From dcb9630633948928c8376f3816d4fd69a719222a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 13 Jun 2019 09:43:10 +0200 Subject: [PATCH 2/2] add test file highlighting the bug fixed by the previous commit --- .../Boolean_set_operations_2/bug_3989.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Boolean_set_operations_2/test/Boolean_set_operations_2/bug_3989.cpp diff --git a/Boolean_set_operations_2/test/Boolean_set_operations_2/bug_3989.cpp b/Boolean_set_operations_2/test/Boolean_set_operations_2/bug_3989.cpp new file mode 100644 index 00000000000..36c1354c549 --- /dev/null +++ b/Boolean_set_operations_2/test/Boolean_set_operations_2/bug_3989.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_exact_constructions_kernel K; + + +int main() +{ + CGAL::Polygon_2 ob; + ob.push_back(CGAL::Point_2(1, 1)); + ob.push_back(CGAL::Point_2(1, 0)); + ob.push_back(CGAL::Point_2(6, 0)); + ob.push_back(CGAL::Point_2(6, 7)); + ob.push_back(CGAL::Point_2(0, 7)); + ob.push_back(CGAL::Point_2(0, 1)); + + CGAL::Polygon_2 h; + h.push_back(CGAL::Point_2(2, 1)); + h.push_back(CGAL::Point_2(2, 2)); + h.push_back(CGAL::Point_2(3, 2)); + h.push_back(CGAL::Point_2(3, 3)); + h.push_back(CGAL::Point_2(2, 3)); + h.push_back(CGAL::Point_2(2, 4)); + h.push_back(CGAL::Point_2(3, 4)); + h.push_back(CGAL::Point_2(3, 5)); + h.push_back(CGAL::Point_2(4, 5)); + h.push_back(CGAL::Point_2(4, 1)); + + CGAL::Polygon_with_holes_2 ob_with_holes(ob); + ob_with_holes.add_hole(h); + CGAL::Polygon_set_2 inter(ob_with_holes); + + CGAL::Polygon_2 new_poly; + new_poly.push_back(CGAL::Point_2(1, 1)); + new_poly.push_back(CGAL::Point_2(2, 1)); + new_poly.push_back(CGAL::Point_2(2, 2)); + new_poly.push_back(CGAL::Point_2(2, 3)); + new_poly.push_back(CGAL::Point_2(2, 4)); + new_poly.push_back(CGAL::Point_2(2, 5)); + new_poly.push_back(CGAL::Point_2(3, 5)); + new_poly.push_back(CGAL::Point_2(4, 5)); + new_poly.push_back(CGAL::Point_2(4, 6)); + new_poly.push_back(CGAL::Point_2(1, 6)); + + inter.difference(new_poly); +} \ No newline at end of file