From 75c2ac5a68633c3a981833e7899d22fd6d775459 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Mon, 13 Oct 2025 17:18:56 +0200 Subject: [PATCH] bug-fix: use longest border polyline to compute the normal fix bug of Thingi 1439534 --- ...ing_constrained_Delaunay_triangulation_3.h | 23 +++++++++++++++++++ .../cdt_3_from_off.cpp | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Constrained_triangulation_3/include/CGAL/Conforming_constrained_Delaunay_triangulation_3.h b/Constrained_triangulation_3/include/CGAL/Conforming_constrained_Delaunay_triangulation_3.h index 4e576dcccfd..ecce1d7c23c 100644 --- a/Constrained_triangulation_3/include/CGAL/Conforming_constrained_Delaunay_triangulation_3.h +++ b/Constrained_triangulation_3/include/CGAL/Conforming_constrained_Delaunay_triangulation_3.h @@ -725,6 +725,29 @@ public: std::make_move_iterator(other_polylines.end())); } + if(polylines.size() > 1) { + double max_sq_length = 0; + auto longest_it = polylines.begin(); + for(auto it = polylines.begin(); it != polylines.end(); ++it) { + auto& polyline = *it; + using CGAL::Bbox_3; + Bbox_3 bb; + for(auto v : polyline) { + bb = bb + Bbox_3(get(mesh_vp_map, v).bbox()); + } + double sq_diagonal_length = CGAL::square(bb.xmax() - bb.xmin()) + + CGAL::square(bb.ymax() - bb.ymin()) + + CGAL::square(bb.zmax() - bb.zmin()); + if(sq_diagonal_length > max_sq_length) { + max_sq_length = sq_diagonal_length; + longest_it = it; + } + } + if(longest_it != polylines.begin()) { + std::iter_swap(longest_it, polylines.begin()); + } + } + std::optional face_index; for(auto& polyline : polylines) { CGAL_assertion(!polyline.empty() && polyline.front() == polyline.back()); diff --git a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp index 526d14ea0a7..2acb2888c37 100644 --- a/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp +++ b/Constrained_triangulation_3/test/Constrained_triangulation_3/cdt_3_from_off.cpp @@ -721,6 +721,29 @@ int go(Mesh mesh, CDT_options options) { std::make_move_iterator(other_polylines.end())); } + if(polylines.size() > 1) { + double max_sq_length = 0; + auto longest_it = polylines.begin(); + for(auto it = polylines.begin(); it != polylines.end(); ++it) { + auto& polyline = *it; + using CGAL::Bbox_3; + Bbox_3 bb; + for(auto v : polyline) { + bb = bb + Bbox_3(get(mesh_vp_map, v).bbox()); + } + double sq_diagonal_length = CGAL::square(bb.xmax() - bb.xmin()) + + CGAL::square(bb.ymax() - bb.ymin()) + + CGAL::square(bb.zmax() - bb.zmin()); + if(sq_diagonal_length > max_sq_length) { + max_sq_length = sq_diagonal_length; + longest_it = it; + } + } + if(longest_it != polylines.begin()) { + std::iter_swap(longest_it, polylines.begin()); + } + } + std::optional face_index; for(auto& polyline : polylines) { CGAL_assertion(!polyline.empty() && polyline.front() == polyline.back());