From 3bd448d1a88a21ccbcc99ef5a9499338a712bad6 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 28 Feb 2024 14:28:00 +0000 Subject: [PATCH 1/4] Polygon: Avoid stackoverflow when summing exact numbers --- Polygon/include/CGAL/Polygon_2_algorithms.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Polygon/include/CGAL/Polygon_2_algorithms.h b/Polygon/include/CGAL/Polygon_2_algorithms.h index 5c836466c11..dc8f9c8708f 100644 --- a/Polygon/include/CGAL/Polygon_2_algorithms.h +++ b/Polygon/include/CGAL/Polygon_2_algorithms.h @@ -24,6 +24,7 @@ #include #include #include +#include #include /// @@ -153,6 +154,7 @@ area_2( ForwardIterator first, ForwardIterator last, ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); + exact(result); second = third; } } @@ -190,6 +192,7 @@ polygon_area_2( ForwardIterator first, ForwardIterator last, ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); + exact(result); second = third; } return result; From 2c8567ed16d16650e517cbba7688965f964ee313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 6 Mar 2024 10:48:52 +0100 Subject: [PATCH 2/4] add overload for Quotent as specialization for std::arithmetic result in undefined behavior --- Filtered_kernel/include/CGAL/Lazy.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 463ef501b34..dcfb877ee8e 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -108,6 +108,10 @@ templateinline std::enable_if_t::value||std::is_e templateinline std::enable_if_t::value||std::is_enum::value, T> exact (T d){return d;} templateinline std::enable_if_t::value||std::is_enum::value, int> depth(T){return -1;} +templateinline std::enable_if_t::value, Quotient> approx(Quotient d){return d;} +templateinline std::enable_if_t::value, Quotient> exact (Quotient d){return d;} +templateinline std::enable_if_t::value, int> depth(Quotient){return -1;} + // For tag classes: Return_base_tag, Homogeneous_tag, Null_vector, Origin templateinline std::enable_if_t::value, T> exact(T){return {};} templateinline std::enable_if_t::value, T> approx(T){return {};} From 9b4f35dfa1ef528794360f501ead82594fff68d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 6 Mar 2024 11:32:30 +0100 Subject: [PATCH 3/4] fix dependencies --- Bounding_volumes/package_info/Bounding_volumes/dependencies | 1 + Generator/package_info/Generator/dependencies | 1 + Inscribed_areas/package_info/Inscribed_areas/dependencies | 1 + Nef_2/package_info/Nef_2/dependencies | 1 + Polygon/package_info/Polygon/dependencies | 3 +++ .../package_info/Set_movable_separability_2/dependencies | 3 +++ Stream_support/package_info/Stream_support/dependencies | 1 + 7 files changed, 11 insertions(+) diff --git a/Bounding_volumes/package_info/Bounding_volumes/dependencies b/Bounding_volumes/package_info/Bounding_volumes/dependencies index 99a12a27c82..6a7b86ebd72 100644 --- a/Bounding_volumes/package_info/Bounding_volumes/dependencies +++ b/Bounding_volumes/package_info/Bounding_volumes/dependencies @@ -4,6 +4,7 @@ Cartesian_kernel Circulator Distance_2 Distance_3 +Filtered_kernel Installation Intersections_2 Intersections_3 diff --git a/Generator/package_info/Generator/dependencies b/Generator/package_info/Generator/dependencies index 04faaf3547d..925a743b87c 100644 --- a/Generator/package_info/Generator/dependencies +++ b/Generator/package_info/Generator/dependencies @@ -1,6 +1,7 @@ Algebraic_foundations BGL Circulator +Filtered_kernel Generator Installation Interval_support diff --git a/Inscribed_areas/package_info/Inscribed_areas/dependencies b/Inscribed_areas/package_info/Inscribed_areas/dependencies index da58f1b4f08..fc0704df443 100644 --- a/Inscribed_areas/package_info/Inscribed_areas/dependencies +++ b/Inscribed_areas/package_info/Inscribed_areas/dependencies @@ -1,6 +1,7 @@ Algebraic_foundations Circulator Distance_2 +Filtered_kernel Inscribed_areas Installation Interval_support diff --git a/Nef_2/package_info/Nef_2/dependencies b/Nef_2/package_info/Nef_2/dependencies index cca2b94b65f..1abad5d8686 100644 --- a/Nef_2/package_info/Nef_2/dependencies +++ b/Nef_2/package_info/Nef_2/dependencies @@ -5,6 +5,7 @@ Cartesian_kernel Circulator Distance_2 Distance_3 +Filtered_kernel HalfedgeDS Hash_map Homogeneous_kernel diff --git a/Polygon/package_info/Polygon/dependencies b/Polygon/package_info/Polygon/dependencies index 3312eb37e46..7ed360974c5 100644 --- a/Polygon/package_info/Polygon/dependencies +++ b/Polygon/package_info/Polygon/dependencies @@ -1,8 +1,11 @@ Algebraic_foundations Circulator +Filtered_kernel GraphicsView Installation +Interval_support Kernel_23 +Modular_arithmetic Number_types Polygon Profiling_tools diff --git a/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies b/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies index e88f195eeab..c84b7694460 100644 --- a/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies +++ b/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies @@ -1,7 +1,10 @@ Algebraic_foundations Circulator +Filtered_kernel Installation +Interval_support Kernel_23 +Modular_arithmetic Number_types Polygon Profiling_tools diff --git a/Stream_support/package_info/Stream_support/dependencies b/Stream_support/package_info/Stream_support/dependencies index 86fd53b13ac..f45a1a985bf 100644 --- a/Stream_support/package_info/Stream_support/dependencies +++ b/Stream_support/package_info/Stream_support/dependencies @@ -1,6 +1,7 @@ Algebraic_foundations BGL Circulator +Filtered_kernel Installation Interval_support Kernel_23 From f34745c4d87c94f954fe1e6b7a3a1b3dbdf85e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 14 Mar 2024 09:14:47 +0100 Subject: [PATCH 4/4] use a functor for collapsing the DAG to not depend on Filtered_kernel nor inclusion order --- .../Bounding_volumes/dependencies | 1 - Filtered_kernel/include/CGAL/Lazy.h | 11 +++++++++ Generator/package_info/Generator/dependencies | 1 - .../Surface_mesh_geodesic_distances_3.h | 2 ++ .../package_info/Heat_method_3/dependencies | 1 - .../package_info/Inscribed_areas/dependencies | 1 - Nef_2/package_info/Nef_2/dependencies | 1 - Number_types/include/CGAL/utils_classes.h | 11 +++++++++ Polygon/include/CGAL/Polygon_2_algorithms.h | 8 ++++--- Polygon/package_info/Polygon/dependencies | 3 --- .../CGAL/Polygon_mesh_processing/measure.h | 24 ++++++++++++------- .../Set_movable_separability_2/dependencies | 3 --- .../package_info/Stream_support/dependencies | 1 - 13 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Bounding_volumes/package_info/Bounding_volumes/dependencies b/Bounding_volumes/package_info/Bounding_volumes/dependencies index 6a7b86ebd72..99a12a27c82 100644 --- a/Bounding_volumes/package_info/Bounding_volumes/dependencies +++ b/Bounding_volumes/package_info/Bounding_volumes/dependencies @@ -4,7 +4,6 @@ Cartesian_kernel Circulator Distance_2 Distance_3 -Filtered_kernel Installation Intersections_2 Intersections_3 diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index dcfb877ee8e..95d79065451 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -117,6 +117,17 @@ templateinline std::enable_if_t::value, T> exact(T){re templateinline std::enable_if_t::value, T> approx(T){return {};} templateinline std::enable_if_t::value, int> depth(T){return -1;} +namespace internal{ +template +struct Evaluate> +{ + void operator()(const Lazy& l) + { + exact(l); + } +}; +} // internal namespace + // For an iterator, exact/approx applies to the objects it points to template ::value>> auto exact(T const& t) {return make_transforming_iterator(t,[](auto const&u)->decltype(auto){return CGAL::exact(u);});} diff --git a/Generator/package_info/Generator/dependencies b/Generator/package_info/Generator/dependencies index 925a743b87c..04faaf3547d 100644 --- a/Generator/package_info/Generator/dependencies +++ b/Generator/package_info/Generator/dependencies @@ -1,7 +1,6 @@ Algebraic_foundations BGL Circulator -Filtered_kernel Generator Installation Interval_support diff --git a/Heat_method_3/include/CGAL/Heat_method_3/Surface_mesh_geodesic_distances_3.h b/Heat_method_3/include/CGAL/Heat_method_3/Surface_mesh_geodesic_distances_3.h index 64c1782bb9c..46441d6f8e2 100644 --- a/Heat_method_3/include/CGAL/Heat_method_3/Surface_mesh_geodesic_distances_3.h +++ b/Heat_method_3/include/CGAL/Heat_method_3/Surface_mesh_geodesic_distances_3.h @@ -25,6 +25,8 @@ #include #include #include +#include + #ifdef CGAL_EIGEN3_ENABLED #include #endif diff --git a/Heat_method_3/package_info/Heat_method_3/dependencies b/Heat_method_3/package_info/Heat_method_3/dependencies index 50488d5544f..f69807f53d7 100644 --- a/Heat_method_3/package_info/Heat_method_3/dependencies +++ b/Heat_method_3/package_info/Heat_method_3/dependencies @@ -4,7 +4,6 @@ Cartesian_kernel Circulator Distance_2 Distance_3 -Filtered_kernel Heat_method_3 Installation Interval_support diff --git a/Inscribed_areas/package_info/Inscribed_areas/dependencies b/Inscribed_areas/package_info/Inscribed_areas/dependencies index fc0704df443..da58f1b4f08 100644 --- a/Inscribed_areas/package_info/Inscribed_areas/dependencies +++ b/Inscribed_areas/package_info/Inscribed_areas/dependencies @@ -1,7 +1,6 @@ Algebraic_foundations Circulator Distance_2 -Filtered_kernel Inscribed_areas Installation Interval_support diff --git a/Nef_2/package_info/Nef_2/dependencies b/Nef_2/package_info/Nef_2/dependencies index 1abad5d8686..cca2b94b65f 100644 --- a/Nef_2/package_info/Nef_2/dependencies +++ b/Nef_2/package_info/Nef_2/dependencies @@ -5,7 +5,6 @@ Cartesian_kernel Circulator Distance_2 Distance_3 -Filtered_kernel HalfedgeDS Hash_map Homogeneous_kernel diff --git a/Number_types/include/CGAL/utils_classes.h b/Number_types/include/CGAL/utils_classes.h index 06a569a6d8b..1b4eb95ce89 100644 --- a/Number_types/include/CGAL/utils_classes.h +++ b/Number_types/include/CGAL/utils_classes.h @@ -266,6 +266,17 @@ class Is_valid }; }; +namespace internal +{ +// utility class to be used for calling exact(Lazy) when doing accumulation with EPECK +template +struct Evaluate +{ + void operator()(const NT&) + {} +}; +} // internal namespace + } //namespace CGAL #endif // CGAL_UTILS_CLASSES_H diff --git a/Polygon/include/CGAL/Polygon_2_algorithms.h b/Polygon/include/CGAL/Polygon_2_algorithms.h index dc8f9c8708f..40b1e06a9c7 100644 --- a/Polygon/include/CGAL/Polygon_2_algorithms.h +++ b/Polygon/include/CGAL/Polygon_2_algorithms.h @@ -24,8 +24,8 @@ #include #include #include -#include #include +#include /// namespace CGAL { @@ -143,6 +143,7 @@ area_2( ForwardIterator first, ForwardIterator last, const PolygonTraits& traits) { typedef typename PolygonTraits::FT FT; + internal::Evaluate evaluate; result = FT(0); // check if the polygon is empty if (first == last) return; @@ -154,7 +155,7 @@ area_2( ForwardIterator first, ForwardIterator last, ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); - exact(result); + evaluate(result); second = third; } } @@ -181,6 +182,7 @@ polygon_area_2( ForwardIterator first, ForwardIterator last, const PolygonTraits& traits) { typedef typename PolygonTraits::FT FT; + internal::Evaluate evaluate; FT result = FT(0); // check if the polygon is empty if (first == last) return result; @@ -192,7 +194,7 @@ polygon_area_2( ForwardIterator first, ForwardIterator last, ForwardIterator third = second; while (++third != last) { result = result + compute_area_2(*first, *second, *third); - exact(result); + evaluate(result); second = third; } return result; diff --git a/Polygon/package_info/Polygon/dependencies b/Polygon/package_info/Polygon/dependencies index 7ed360974c5..3312eb37e46 100644 --- a/Polygon/package_info/Polygon/dependencies +++ b/Polygon/package_info/Polygon/dependencies @@ -1,11 +1,8 @@ Algebraic_foundations Circulator -Filtered_kernel GraphicsView Installation -Interval_support Kernel_23 -Modular_arithmetic Number_types Polygon Profiling_tools diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h index a0841748aee..87946231227 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/measure.h @@ -23,9 +23,7 @@ #include #include #include - - -#include // needed for CGAL::exact(FT)/CGAL::exact(Lazy_exact_nt) +#include #include #include @@ -261,12 +259,14 @@ face_border_length(typename boost::graph_traits::halfedge_descripto const PolygonMesh& pmesh, const NamedParameters& np = parameters::default_values()) { - typename GetGeomTraits::type::FT result = 0; + using FT = typename GetGeomTraits::type::FT; + ::CGAL::internal::Evaluate evaluate; + FT result = 0; for(typename boost::graph_traits::halfedge_descriptor haf : halfedges_around_face(h, pmesh)) { result += edge_length(haf, pmesh, np); - exact(result); + evaluate(result); } return result; @@ -559,11 +559,14 @@ area(FaceRange face_range, { typedef typename boost::graph_traits::face_descriptor face_descriptor; - typename GetGeomTraits::type::FT result = 0; + using FT = typename GetGeomTraits::type::FT; + FT result = 0; + ::CGAL::internal::Evaluate evaluate; + for(face_descriptor f : face_range) { result += face_area(f, tmesh, np); - exact(result); + evaluate(result); } return result; @@ -676,7 +679,10 @@ volume(const TriangleMesh& tmesh, typedef typename boost::graph_traits::face_descriptor face_descriptor; - typename GetGeomTraits::type::FT volume = 0; + using FT = typename GetGeomTraits::type::FT; + ::CGAL::internal::Evaluate evaluate; + + FT volume = 0; typename CGAL::Kernel_traits::type>::Kernel::Compute_volume_3 cv3; @@ -686,7 +692,7 @@ volume(const TriangleMesh& tmesh, get(vpm, target(halfedge(f, tmesh), tmesh)), get(vpm, target(next(halfedge(f, tmesh), tmesh), tmesh)), get(vpm, target(prev(halfedge(f, tmesh), tmesh), tmesh))); - exact(volume); + evaluate(volume); } return volume; diff --git a/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies b/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies index c84b7694460..e88f195eeab 100644 --- a/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies +++ b/Set_movable_separability_2/package_info/Set_movable_separability_2/dependencies @@ -1,10 +1,7 @@ Algebraic_foundations Circulator -Filtered_kernel Installation -Interval_support Kernel_23 -Modular_arithmetic Number_types Polygon Profiling_tools diff --git a/Stream_support/package_info/Stream_support/dependencies b/Stream_support/package_info/Stream_support/dependencies index f45a1a985bf..86fd53b13ac 100644 --- a/Stream_support/package_info/Stream_support/dependencies +++ b/Stream_support/package_info/Stream_support/dependencies @@ -1,7 +1,6 @@ Algebraic_foundations BGL Circulator -Filtered_kernel Installation Interval_support Kernel_23