diff --git a/BGL/include/CGAL/boost/graph/Euler_operations.h b/BGL/include/CGAL/boost/graph/Euler_operations.h index f8c79165bc5..f788ec18113 100644 --- a/BGL/include/CGAL/boost/graph/Euler_operations.h +++ b/BGL/include/CGAL/boost/graph/Euler_operations.h @@ -1575,9 +1575,8 @@ collapse_edge(typename boost::graph_traits::edge_descriptor e, bool lBottomFaceExists = ! is_border(qp,g); bool lTopLeftFaceExists = lTopFaceExists && ! is_border(pt,g); bool lBottomRightFaceExists = lBottomFaceExists && ! is_border(qb,g); - - CGAL_precondition( !lTopFaceExists || (lTopFaceExists && ( degree(target(pt, g), g) > 2 ) ) ) ; - CGAL_precondition( !lBottomFaceExists || (lBottomFaceExists && ( degree(target(qb, g), g) > 2 ) ) ) ; + bool lBottomIsTriangle = lBottomFaceExists && next(next(qp, g), g) == prev(qp,g); + bool lTopIsTriangle = lTopFaceExists && next(next(pq, g), g) == prev(pq,g); vertex_descriptor q = target(pq, g); vertex_descriptor p = source(pq, g); @@ -1585,7 +1584,7 @@ collapse_edge(typename boost::graph_traits::edge_descriptor e, bool lP_Erased = false; - if ( lTopFaceExists ) + if ( lTopFaceExists && lTopIsTriangle) { CGAL_precondition( ! is_border(opposite(pt, g),g) ) ; // p-q-t is a face of the mesh if ( lTopLeftFaceExists ) @@ -1612,7 +1611,7 @@ collapse_edge(typename boost::graph_traits::edge_descriptor e, } } - if ( lBottomFaceExists ) + if ( lBottomFaceExists && lBottomIsTriangle) { CGAL_precondition( ! is_border(opposite(qb, g),g) ) ; // p-q-b is a face of the mesh if ( lBottomRightFaceExists ) diff --git a/BGL/test/BGL/data/polygon_mesh_to_collapse.off b/BGL/test/BGL/data/polygon_mesh_to_collapse.off new file mode 100644 index 00000000000..1a25e940585 --- /dev/null +++ b/BGL/test/BGL/data/polygon_mesh_to_collapse.off @@ -0,0 +1,42 @@ +OFF +25 13 0 + +0.39160239696502686 1.3864846229553223 4.8046874923102223e-08 +0.053782559931278229 1.3864846229553223 4.8046874923102223e-08 +-0.94644606113433838 1.6651756763458252 4.8046874923102223e-08 +-1.3082554340362549 1.7385153770446777 4.8046874923102223e-08 +-1.3033660650253296 1.1860226392745972 4.8046874923102223e-08 +1.61628258228302 -0.17601536214351654 4.8046874923102223e-08 +0.55834579467773438 -0.19216139614582062 4.8046874923102223e-08 +0.053782559931278229 -0.17601536214351654 4.8046874923102223e-08 +-0.24240998923778534 -0.22679123282432556 4.8046874923102223e-08 +-0.58168435096740723 -0.25845989584922791 4.8046874923102223e-08 +-1.2915089130401611 -0.17601536214351654 4.8046874923102223e-08 +-1.50871741771698 -0.17601536214351654 4.8046874923102223e-08 +1.61628258228302 -1.7385153770446777 4.8046874923102223e-08 +1.1978726387023926 -1.7385153770446777 4.8046874923102223e-08 +0.71942150592803955 -1.7385153770446777 4.8046874923102223e-08 +0.053782559931278229 -1.7385153770446777 4.8046874923102223e-08 +-0.73973840475082397 -1.7385153770446777 4.8046874923102223e-08 +1.61628258228302 0.36264327168464661 4.8046874923102223e-08 +-0.26156377792358398 0.45463424921035767 4.8046874923102223e-08 +-0.028661971911787987 -0.78840988874435425 4.8046874923102223e-08 +0.053782559931278229 -1.2213115692138672 4.8046874923102223e-08 +-1.5918357372283936 1.5331641435623169 4.8046874923102223e-08 +-1.6162823438644409 0.87338578701019287 4.8046874923102223e-08 +-1.50871741771698 -0.0072435899637639523 4.8046874923102223e-08 +-1.50871741771698 -1.3000825643539429 4.8046874923102223e-08 +7 18 2 3 4 22 9 8 +3 2 18 1 +7 18 7 6 5 17 0 1 +7 12 5 6 7 8 19 13 +6 11 24 16 15 20 10 +3 9 19 8 +4 10 20 19 9 +3 7 18 8 +3 14 20 15 +4 13 19 20 14 +3 3 21 4 +4 9 22 23 10 +3 10 23 11 + diff --git a/BGL/test/BGL/test_Collapse_edge.cpp b/BGL/test/BGL/test_Collapse_edge.cpp index 69f1c347a5e..ecbaff8fe36 100644 --- a/BGL/test/BGL/test_Collapse_edge.cpp +++ b/BGL/test/BGL/test_Collapse_edge.cpp @@ -2,7 +2,6 @@ #include #include - #include #include @@ -213,12 +212,30 @@ collapse_edge_test() assert(found == 2); CGAL::clear(test_mesh); } + // Case 6 non pure triangle mesh + { + Mesh ref; + if(!CGAL::IO::read_OFF("data/polygon_mesh_to_collapse.off", ref)) + { + std::cout << "Error reading file: data/polygon_mesh_to_collapse.off" << std::endl; + exit(1); + } + std::size_t nbe=halfedges(ref).size(); + for (std::size_t i=0; i< nbe; ++i) + { + Mesh m = ref; + auto h = *std::next(halfedges(m).begin(), i); + + if (CGAL::Euler::does_satisfy_link_condition(edge(h,m),m)) + CGAL::Euler::collapse_edge(edge(h,m), m); + assert(CGAL::is_valid_polygon_mesh(m)); + } + } } int main() { - collapse_edge_test(); collapse_edge_test();