From 7b2c8b40e1abbd8950789b3bcb4509b49c963b0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sun, 20 Apr 2025 14:59:29 +0200 Subject: [PATCH] Add Kernel_23::Compare_squared_radius_2 --- .../include/CGAL/Cartesian/function_objects.h | 53 ++++++++++++++++++- .../include/CGAL/constructions/kernel_ftC2.h | 48 +++++++++-------- .../CGAL/Homogeneous/function_objects.h | 1 + .../include/CGAL/Kernel/global_functions_2.h | 30 +++++++++++ .../CGAL/Kernel/global_functions_internal_2.h | 34 ++++++++++++ .../include/CGAL/Kernel/interface_macros.h | 2 + 6 files changed, 143 insertions(+), 25 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 937bcbe6e23..1363b56ef69 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -656,6 +656,42 @@ public: } }; + template + class Compare_squared_radius_2 + { + typedef typename K::Comparison_result Comparison_result; + typedef typename K::Point_2 Point_2; + typedef typename K::FT FT; + + public: + Comparison_result + operator()(const Point_2& p, const Point_2& q, const Point_2& r, const FT& ft) const + { + FT num, den; + squared_radiusC2(p.x(), p.y(), + q.x(), q.y(), + r.x(), r.y(), + num, den); + return CGAL::compare(num, den * ft); + } + + Comparison_result + operator()(const Point_2& p, const Point_2& q, const FT& ft) const + { + FT num, den; + squared_radiusC2(p.x(), p.y(), + q.x(), q.y(), + num, den); + return CGAL::compare(num, den * ft); + } + + Comparison_result + operator()(const Point_2&, const FT& ft) const + { + return - CGAL_NTS sign(ft); + } + }; + template class Compare_squared_radius_3 { @@ -1178,11 +1214,24 @@ public: FT operator()( const Point_2& p, const Point_2& q) const - { return squared_radiusC2(p.x(), p.y(), q.x(), q.y()); } + { + FT num, den; + squared_radiusC2(p.x(), p.y(), + q.x(), q.y(), + num, den); + return num / den; + } FT operator()( const Point_2& p, const Point_2& q, const Point_2& r) const - { return squared_radiusC2(p.x(), p.y(), q.x(), q.y(), r.x(), r.y()); } + { + FT num, den; + squared_radiusC2(p.x(), p.y(), + q.x(), q.y(), + r.x(), r.y(), + num, den); + return num / den; + } }; } //namespace CartesianKernelFunctors diff --git a/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h b/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h index d4a62c21c91..b75744efa37 100644 --- a/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h +++ b/Cartesian_kernel/include/CGAL/constructions/kernel_ftC2.h @@ -338,47 +338,49 @@ line_project_pointC2(const FT &la, const FT &lb, const FT &lc, template < class FT > CGAL_KERNEL_MEDIUM_INLINE -FT +void squared_radiusC2(const FT &px, const FT &py, const FT &qx, const FT &qy, const FT &rx, const FT &ry, - FT &x, FT &y ) + FT &num, FT &den) { - circumcenter_translateC2(qx-px, qy-py, rx-px, ry-py, x, y); - FT r2 = CGAL_NTS square(x) + CGAL_NTS square(y); - x += px; - y += py; - return r2; -} + // Translate r to origin to simplify the expression. + FT prx = px - rx; + FT pry = py - ry; + FT pr2 = CGAL_NTS square(prx) + CGAL_NTS square(pry); + FT qrx = qx - rx; + FT qry = qy - ry; + FT qr2 = CGAL_NTS square(qrx) + CGAL_NTS square(qry); -template < class FT > -CGAL_KERNEL_MEDIUM_INLINE -FT -squared_radiusC2(const FT &px, const FT &py, - const FT &qx, const FT &qy, - const FT &rx, const FT &ry) -{ - FT x, y; - circumcenter_translateC2(qx-px, qy-py, rx-px, ry-py, x, y); - return CGAL_NTS square(x) + CGAL_NTS square(y); + FT num_x = determinant(qry, qr2, + pry, pr2); + FT num_y = determinant(qrx, qr2, + prx, pr2); + FT dden = determinant(qrx, qry, + prx, pry); + + num = CGAL_NTS square(num_x) + CGAL_NTS square(num_y); + den = CGAL_NTS square(2 * dden); } template < class FT > inline FT -squared_distanceC2( const FT &px, const FT &py, - const FT &qx, const FT &qy) +squared_distanceC2(const FT &px, const FT &py, + const FT &qx, const FT &qy) { return CGAL_NTS square(px-qx) + CGAL_NTS square(py-qy); } template < class FT > inline -FT +void squared_radiusC2(const FT &px, const FT &py, - const FT &qx, const FT &qy) + const FT &qx, const FT &qy, + FT &num, FT &den) { - return squared_distanceC2(px, py,qx, qy) / 4; + num = squared_distanceC2(px, py,qx, qy); + den = 4; } template < class FT > diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 00b6c05b1ad..6c14ddd06b5 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -34,6 +34,7 @@ namespace HomogeneousKernelFunctors { using CartesianKernelFunctors::Are_parallel_2; using CartesianKernelFunctors::Are_parallel_3; using CartesianKernelFunctors::Compute_squared_area_3; + using CartesianKernelFunctors::Compare_squared_radius_2; using CartesianKernelFunctors::Compare_squared_radius_3; using CartesianKernelFunctors::Collinear_3; using CartesianKernelFunctors::Construct_line_3; diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_2.h index e90685d7b0d..2d56f6a5c36 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_2.h @@ -365,6 +365,36 @@ compare_slopes(const Segment_2 &s1, const Segment_2 &s2) } #endif +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const Point_2 &p, + const typename K::FT &sr) +{ + return internal::compare_squared_radius(p, sr, K()); +} + +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const Point_2 &p, + const Point_2 &q, + const typename K::FT &sr) +{ + return internal::compare_squared_radius(p, q, sr, K()); +} + +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const Point_2 &p, + const Point_2 &q, + const Point_2 &r, + const typename K::FT &sr) +{ + return internal::compare_squared_radius(p, q, r, sr, K()); +} + template < class K > inline typename K::Comparison_result diff --git a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h index a7407a9fd74..1748a4425f0 100644 --- a/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h +++ b/Kernel_23/include/CGAL/Kernel/global_functions_internal_2.h @@ -383,6 +383,40 @@ compare_slope(const typename K::Point_2 &s1s, return k.compare_slope_2_object()(s1s, s1t, s2s, s2t); } + +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const typename K::Point_2 &p, + const typename K::FT &sr, + const K& k) +{ + return k.compare_squared_radius_2_object()(p, sr); +} + +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const typename K::Point_2 &p, + const typename K::Point_2 &q, + const typename K::FT &sr, + const K& k) +{ + return k.compare_squared_radius_2_object()(p, q, sr); +} + +template < class K > +inline +typename K::Comparison_result +compare_squared_radius(const typename K::Point_2 &p, + const typename K::Point_2 &q, + const typename K::Point_2 &r, + const typename K::FT &sr, + const K& k) +{ + return k.compare_squared_radius_2_object()(p, q, r, sr); +} + template < class K > inline typename K::Comparison_result diff --git a/Kernel_23/include/CGAL/Kernel/interface_macros.h b/Kernel_23/include/CGAL/Kernel/interface_macros.h index a2314aef1b7..583eb01a608 100644 --- a/Kernel_23/include/CGAL/Kernel/interface_macros.h +++ b/Kernel_23/include/CGAL/Kernel/interface_macros.h @@ -122,6 +122,8 @@ CGAL_Kernel_pred(Compare_squared_distance_2, compare_squared_distance_2_object) CGAL_Kernel_pred(Compare_squared_distance_3, compare_squared_distance_3_object) +CGAL_Kernel_pred(Compare_squared_radius_2, + compare_squared_radius_2_object) CGAL_Kernel_pred(Compare_squared_radius_3, compare_squared_radius_3_object) CGAL_Kernel_pred(Compare_weighted_squared_radius_3,