From 342fc2b18f4db0beba8159a197fa4e072a17dccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Fri, 21 Nov 2025 11:16:23 +0100 Subject: [PATCH] one more tangency fix --- .../Polygon_mesh_processing/refine_with_plane.h | 17 +++++++++++++---- .../Polygon_mesh_processing/test_pmp_clip.cpp | 15 ++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/refine_with_plane.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/refine_with_plane.h index 1561cc1a2ba..5334d89daa0 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/refine_with_plane.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/refine_with_plane.h @@ -484,7 +484,6 @@ void refine_with_plane(PolygonMesh& pm, else { // sort hedges to make them match - CGAL_assertion(!triangulate); // TODO: need mechanism to make it robust even with EPICK auto less_hedge = [&pm, vpm](halfedge_descriptor h1, halfedge_descriptor h2) { @@ -492,13 +491,23 @@ void refine_with_plane(PolygonMesh& pm, }; std::sort(f_and_hs.second.begin(), f_and_hs.second.end(), less_hedge); - if (f_and_hs.second.front()==*std::next(f_and_hs.second.begin())) - f_and_hs.second.erase(f_and_hs.second.begin()); + if (f_and_hs.second[0]==f_and_hs.second[1]) + { + halfedge_descriptor h = f_and_hs.second[0]; + if ( get(vertex_os, source(h, pm))==ON_ORIENTED_BOUNDARY || get(vertex_os, target(next(h, pm), pm))==ON_ORIENTED_BOUNDARY) + f_and_hs.second.erase(f_and_hs.second.begin()); + } if (f_and_hs.second.back()==*std::prev(f_and_hs.second.end(),2)) - f_and_hs.second.pop_back(); + { + halfedge_descriptor h = f_and_hs.second.back(); + if ( get(vertex_os, source(h, pm))==ON_ORIENTED_BOUNDARY || get(vertex_os, target(next(h, pm), pm))==ON_ORIENTED_BOUNDARY) + f_and_hs.second.pop_back(); + } + nb_hedges = f_and_hs.second.size(); CGAL_assertion(nb_hedges%2==0); + CGAL_assertion(!triangulate || nb_hedges==2); for (std::size_t i=0; i> c; PMP::refine_with_plane(c, K::Plane_3(1,0,0,-2)); assert(faces(c).size()==2); assert(vertices(c).size()==8); + c.clear(); + std::ifstream("data-clip/c.off") >> c; + PMP::reverse_face_orientations(c); + PMP::refine_with_plane(c, K::Plane_3(1,0,0,-2)); + assert(faces(c).size()==2); + assert(vertices(c).size()==8); } - { TriangleMesh e; std::ifstream("data-clip/ee.off") >> e; @@ -927,7 +931,6 @@ void test_new_clip() assert(faces(e).size()==30); assert(vertices(e).size()==28); } - { TriangleMesh c; std::ifstream("data-clip/c.off") >> c; @@ -980,7 +983,6 @@ void test_new_clip() TriangleMesh c; std::ifstream("data-clip/tgt_case_2.off") >> c; PMP::refine_with_plane(c, K::Plane_3(1,0,0,-384), CGAL::parameters::do_not_triangulate_faces(false)); -std::ofstream("/tmp/ref.off") << c; assert(faces(c).size()==1); assert(vertices(c).size()==13); c.clear(); @@ -1003,7 +1005,6 @@ std::ofstream("/tmp/ref.off") << c; assert(faces(c).size()==6); assert(vertices(c).size()==18); } - { TriangleMesh ele; std::ifstream(CGAL::data_file_path("meshes/elephant.off")) >> ele; @@ -1013,10 +1014,6 @@ std::ofstream("/tmp/ref.off") << c; assert(faces(ele).size()==1220); assert(vertices(ele).size()==691); } - - - - } struct Clip_and_split_visitor