From a676b75ca0a0e7894a3e1451769e21e21b0a971c Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Fri, 17 May 2019 19:48:41 +0200 Subject: [PATCH] Misc fixes for expression templates --- .../Barycentric_coordinates_2/Mean_value_2.h | 4 +- .../internal_functions_on_sphere_3.h | 9 +- ...s_for_voronoi_intersection_cartesian_2_3.h | 10 +-- .../CGAL/natural_neighbor_coordinates_2.h | 2 +- ...s_for_voronoi_intersection_cartesian_2_3.h | 46 +++++----- Number_types/include/CGAL/Root_of_traits.h | 7 +- .../CGAL/Sqrt_extension/Sqrt_extension_type.h | 86 +++++++------------ .../OTR_2/Reconstruction_triangulation_2.h | 2 +- .../Optimal_transportation_reconstruction_2.h | 2 +- .../Periodic_3_triangulation_dummy_36.h | 4 +- .../internal/Snapping/snap.h | 2 +- STL_Extension/include/CGAL/iterator.h | 6 +- 12 files changed, 79 insertions(+), 101 deletions(-) diff --git a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_2.h b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_2.h index af15ec92ac8..7c5c7229db9 100644 --- a/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_2.h +++ b/Barycentric_coordinates_2/include/CGAL/Barycentric_coordinates_2/Mean_value_2.h @@ -336,8 +336,8 @@ private: // Following section 4.2 from [2] we denote P_j = r_j*r_{j+1} + dot_product(d_j, d_{j+1}). // Vector s_i from [1] corresponds to that one with the name d_i in [2]. for(int j = 0; j < n-1; ++j) - P[j] = (CGAL::max)(r[j]*r[j+1] + scalar_product_2(s[j], s[j+1]), FT(0)); - P[n-1] = (CGAL::max)(r[n-1]*r[0] + scalar_product_2(s[n-1], s[0]), FT(0)); + P[j] = CGAL::max(r[j]*r[j+1] + scalar_product_2(s[j], s[j+1]), 0); + P[n-1] = CGAL::max(r[n-1]*r[0] + scalar_product_2(s[n-1], s[0]), 0); // Compute mean value weights using the formula (16) from [2]. // Since the formula (16) always gives positive values, we have to add a proper sign to all the weight functions. diff --git a/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_functions_on_sphere_3.h b/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_functions_on_sphere_3.h index 4e4faeeb0a1..5c77101eab6 100644 --- a/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_functions_on_sphere_3.h +++ b/Circular_kernel_3/include/CGAL/Circular_kernel_3/internal_functions_on_sphere_3.h @@ -29,6 +29,7 @@ #include +#include #include #include @@ -140,10 +141,10 @@ namespace CGAL { { // Should we compare anyway even if they are degenerated? CGAL_kernel_assertion(!(p1.is_degenerate() || p2.is_degenerate())); - if(is_zero(p1.a())) { - if(!is_zero(p2.a())) return false; - if(is_zero(p1.b())) { - if(!is_zero(p2.b())) return false; + if(CGAL::is_zero(p1.a())) { + if(!CGAL::is_zero(p2.a())) return false; + if(CGAL::is_zero(p1.b())) { + if(!CGAL::is_zero(p2.b())) return false; return p1.c() * p2.d() == p1.d() * p2.c(); } return (p2.c() * p1.b() == p1.c() * p2.b()) && diff --git a/Interpolation/include/CGAL/constructions/constructions_for_voronoi_intersection_cartesian_2_3.h b/Interpolation/include/CGAL/constructions/constructions_for_voronoi_intersection_cartesian_2_3.h index 0248bcb6711..a9f1242b338 100644 --- a/Interpolation/include/CGAL/constructions/constructions_for_voronoi_intersection_cartesian_2_3.h +++ b/Interpolation/include/CGAL/constructions/constructions_for_voronoi_intersection_cartesian_2_3.h @@ -83,11 +83,11 @@ plane_centered_circumcenterC3(const RT &ax, const RT &ay, const RT &az, //precondition: p,q,r aren't collinear. //method: // - tranlation of p to the origin. - plane_centered_circumcenter_translateC3(ax-px, ay-py, az-pz, - nx, ny, nz, - qx-px, qy-py,qz-pz, - rx-px, ry-py,rz-pz, - x, y, z); + plane_centered_circumcenter_translateC3(ax-px, ay-py, az-pz, + nx, ny, nz, + qx-px, qy-py,qz-pz, + rx-px, ry-py,rz-pz, + x, y, z); x+=px; y+=py; z+=pz; diff --git a/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h b/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h index d2df19d72f0..11d9ea427e9 100644 --- a/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h +++ b/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h @@ -121,7 +121,7 @@ natural_neighbors_2(const Dt& dt, *out++ = std::make_pair(v1,coef1); *out++ = std::make_pair(v2,coef2); - return make_triple(out, coef1+coef2, true); + return { out, coef1+coef2, true }; } if (lt == Dt::VERTEX) diff --git a/Interpolation/include/CGAL/predicates/predicates_for_voronoi_intersection_cartesian_2_3.h b/Interpolation/include/CGAL/predicates/predicates_for_voronoi_intersection_cartesian_2_3.h index 8066eac9c22..91a1bc4989d 100644 --- a/Interpolation/include/CGAL/predicates/predicates_for_voronoi_intersection_cartesian_2_3.h +++ b/Interpolation/include/CGAL/predicates/predicates_for_voronoi_intersection_cartesian_2_3.h @@ -78,11 +78,11 @@ side_of_plane_centered_sphereC3(const RT &ax, const RT &ay, const RT &az, // - tranlation of p to the origin. // - seperate computation of det and norm of the expression - return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, - nx, ny, nz, - qx-px, qy-py,qz-pz, - rx-px, ry-py,rz-pz, - tx-px, ty-py,tz-pz); + return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, + nx, ny, nz, + qx-px, qy-py,qz-pz, + rx-px, ry-py,rz-pz, + tx-px, ty-py,tz-pz); } template < class RT> @@ -100,25 +100,25 @@ side_of_plane_centered_sphere_translateC3( RT na =nx*ax + ny*ay + nz*az; na *= RT(2.0); - Sign num = sign_of_determinant(qx, qy, qz, q2, - ny, -nx, RT(0), RT(0), - nx, ny, nz, na, - rx, ry, rz, r2); + Sign num = sign_of_determinant(qx, qy, qz, q2, + ny, -nx, 0, 0, + nx, ny, nz, na, + rx, ry, rz, r2); //denumerator: - Sign den = sign_of_determinant(nx,ny,nz, - ny,-nx, RT(0), - qx,qy,qz); + Sign den = sign_of_determinant(nx,ny,nz, + ny,-nx, 0, + qx,qy,qz); if (den==ZERO) { // bad choice: (ny,-nx,0) is coplanar with n,q. // by precondition: q and n may not be collinear // => the cross product q*n is orthogonal to q, n and not coplanar - num = sign_of_determinant(qx, qy, qz, q2, - ny*qz-nz*qy, nz*qx-nx*qz,nx*qy-ny*qx, RT(0), - nx, ny, nz, na, - rx, ry, rz, r2); - den = sign_of_determinant(nx,ny,nz, - ny*qz-nz*qy, nz*qx - nx*qz,nx*qy-ny*qx, - qx,qy,qz); + num = sign_of_determinant(qx, qy, qz, q2, + ny*qz-nz*qy, nz*qx-nx*qz,nx*qy-ny*qx, 0, + nx, ny, nz, na, + rx, ry, rz, r2); + den = sign_of_determinant(nx,ny,nz, + ny*qz-nz*qy, nz*qx - nx*qz,nx*qy-ny*qx, + qx,qy,qz); } CGAL_assertion(den != ZERO); return den * num; @@ -147,10 +147,10 @@ side_of_plane_centered_sphereC3(const RT &ax, const RT &ay, const RT &az, // - tranlation of p to the origin. // - seperate computation of det and nom of the expression - return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, - nx, ny, nz, - qx-px, qy-py,qz-pz, - rx-px, ry-py,rz-pz); + return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, + nx, ny, nz, + qx-px, qy-py,qz-pz, + rx-px, ry-py,rz-pz); } } //namespace CGAL diff --git a/Number_types/include/CGAL/Root_of_traits.h b/Number_types/include/CGAL/Root_of_traits.h index b80e9ccdb2d..36b5faedeff 100644 --- a/Number_types/include/CGAL/Root_of_traits.h +++ b/Number_types/include/CGAL/Root_of_traits.h @@ -33,11 +33,12 @@ namespace CGAL { template < typename NT > struct Root_of_traits; -template < class NT > +template < class NT1, class NT2, class NT3 > inline -typename Root_of_traits< NT >::Root_of_2 -make_root_of_2(const NT &a, const NT &b, const NT &c) +auto +make_root_of_2(const NT1 &a, const NT2 &b, const NT3 &c) { + using NT = std::common_type_t; typename Root_of_traits::Make_root_of_2 make_root_of_2; return make_root_of_2(a,b,c); } diff --git a/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h b/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h index 92c33de4a50..95078bb874a 100644 --- a/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h +++ b/Number_types/include/CGAL/Sqrt_extension/Sqrt_extension_type.h @@ -651,6 +651,37 @@ CGAL::Comparison_result return (EQUAL); } + + private: + template static bool + is_equal (const Sqrt_extension& p1, const Sqrt_extension& p2) + { return (p1-p2).is_zero(); } + template static bool + is_equal (const Sqrt_extension& p1, const Sqrt_extension& p2) + { return ( p1.compare(p2) == CGAL::ZERO ); } + + public: + // BINARY operators + friend bool operator == (const Sqrt_extension& p1, const Sqrt_extension& p2) + { return Sqrt_extension::is_equal(p1, p2); } // if constexpr (ACDE_TAG::value) ... + friend bool operator < (const Sqrt_extension& p1, const Sqrt_extension& p2) + { return ( p1.compare(p2) == CGAL::SMALLER ); } + + // NT + friend bool operator == (const Sqrt_extension& p, const NT& num) + { return (p-num).is_zero();} + friend bool operator < (const Sqrt_extension& p, const NT& num) + { return ( p.compare(num) == CGAL::SMALLER ); } + friend bool operator > (const Sqrt_extension& p, const NT& num) + { return ( p.compare(num) == CGAL::LARGER ); } + + //CGAL_int(NT) + friend bool operator == (const Sqrt_extension& p, CGAL_int(NT) num) + { return (p-num).is_zero();} + friend bool operator < (const Sqrt_extension& p, CGAL_int(NT) num) + { return ( p.compare(num) == CGAL::SMALLER ); } + friend bool operator > (const Sqrt_extension& p, CGAL_int(NT) num) + { return ( p.compare(num) == CGAL::LARGER ); } }; /*! @@ -727,61 +758,6 @@ operator - (const Sqrt_extension& p){ // BINARY -template bool -operator == (const Sqrt_extension& p1, const Sqrt_extension& p2) -{ return (p1-p2).is_zero(); } -template bool -operator == (const Sqrt_extension& p1, const Sqrt_extension& p2) -{ return ( p1.compare(p2) == CGAL::ZERO ); } -template bool -operator < (const Sqrt_extension& p1, const Sqrt_extension& p2) -{ return ( p1.compare(p2) == CGAL::SMALLER ); } - - -// NT -// righthand side -template bool operator == -(const Sqrt_extension& p, const NT& num) -{ return (p-num).is_zero();} -template bool operator < -(const Sqrt_extension& p, const NT& num) -{ return ( p.compare(num) == CGAL::SMALLER ); } -template bool operator > -(const Sqrt_extension& p, const NT& num) -{ return ( p.compare(num) == CGAL::LARGER ); } - -// lefthand side -template bool operator == -(const NT& num, const Sqrt_extension& p) -{ return ( p == num );} -template bool operator < -(const NT& num, const Sqrt_extension& p) -{ return ( p.compare(num) == CGAL::LARGER ); } -template bool operator > -(const NT& num, const Sqrt_extension& p) -{ return ( p.compare(num) == CGAL::SMALLER ); } - - -//CGAL_int(NT) -template bool operator == -(const Sqrt_extension& p, CGAL_int(NT) num) -{ return (p-num).is_zero();} -template bool operator < -(const Sqrt_extension& p, CGAL_int(NT) num) -{ return ( p.compare(num) == CGAL::SMALLER ); } -template bool operator > -(const Sqrt_extension& p, CGAL_int(NT) num) -{ return ( p.compare(num) == CGAL::LARGER ); } - -template bool operator == -(CGAL_int(NT) num, const Sqrt_extension& p) -{ return ( p == num );} -template bool operator < -(CGAL_int(NT) num, const Sqrt_extension& p) -{ return ( p.compare(num) == CGAL::LARGER ); } -template bool operator > -(CGAL_int(NT) num, const Sqrt_extension& p) -{ return ( p.compare(num) == CGAL::SMALLER ); } template inline Sqrt_extension min BOOST_PREVENT_MACRO_SUBSTITUTION( diff --git a/Optimal_transportation_reconstruction_2/include/CGAL/OTR_2/Reconstruction_triangulation_2.h b/Optimal_transportation_reconstruction_2/include/CGAL/OTR_2/Reconstruction_triangulation_2.h index 61d777c50d8..fa5f1bc30e6 100644 --- a/Optimal_transportation_reconstruction_2/include/CGAL/OTR_2/Reconstruction_triangulation_2.h +++ b/Optimal_transportation_reconstruction_2/include/CGAL/OTR_2/Reconstruction_triangulation_2.h @@ -1075,7 +1075,7 @@ public: return false; } - FT value = Dbc <= 0 ? 1 : 2*Dbc; // value used if Dbd or Dac are +infinity + FT value = Dbc <= 0 ? FT(1) : 2*Dbc; // value used if Dbd or Dac are +infinity if ( !is_infinity(Dac) ) { if ( !is_infinity(Dbd)) diff --git a/Optimal_transportation_reconstruction_2/include/CGAL/Optimal_transportation_reconstruction_2.h b/Optimal_transportation_reconstruction_2/include/CGAL/Optimal_transportation_reconstruction_2.h index 7b3e633be32..4ef7e163a56 100644 --- a/Optimal_transportation_reconstruction_2/include/CGAL/Optimal_transportation_reconstruction_2.h +++ b/Optimal_transportation_reconstruction_2/include/CGAL/Optimal_transportation_reconstruction_2.h @@ -686,7 +686,7 @@ public: { if (m_tolerance == (FT)(-1.)) return false; - FT cost = CGAL::approximate_sqrt (pedge.after() / pedge.total_weight()); + FT cost = CGAL::approximate_sqrt (FT(pedge.after() / pedge.total_weight())); return cost > m_tolerance; } diff --git a/Periodic_3_triangulation_3/include/CGAL/internal/Periodic_3_triangulation_dummy_36.h b/Periodic_3_triangulation_3/include/CGAL/internal/Periodic_3_triangulation_dummy_36.h index 7df11065499..af214f77a64 100644 --- a/Periodic_3_triangulation_3/include/CGAL/internal/Periodic_3_triangulation_dummy_36.h +++ b/Periodic_3_triangulation_3/include/CGAL/internal/Periodic_3_triangulation_dummy_36.h @@ -697,8 +697,8 @@ static const int O[216][4] = { vertices[9*i+3*j+k] = _tds.create_vertex(); Point p(k*(1.0/3.0) + i*(1.0/6.0), j*(1.0/3.0) + i*(1.0/6.0), i*(1.0/4.0) ); - p = Point((p.x() > FT(0.9375) ? (std::max)( p.x()-1, FT(0) ) : p.x()), - (p.y() > FT(0.9375) ? (std::max)( p.y()-1, FT(0) ) : p.y()), p.z()); + p = Point((p.x() > FT(0.9375) ? CGAL::max( p.x()-1, 0 ) : p.x()), + (p.y() > FT(0.9375) ? CGAL::max( p.y()-1, 0 ) : p.y()), p.z()); p = Point((domain().xmax()-domain().xmin())*p.x(), (domain().xmax()-domain().xmin())*p.y(), (domain().xmax()-domain().xmin())*p.z()); diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h index 094ffbb7e0a..cd9572bef1f 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Snapping/snap.h @@ -112,7 +112,7 @@ void assign_tolerance_with_local_edge_length_bound(const HalfedgeRange& hrange, std::cout << "tolerance at vd: " /*<< vd */ << " [" << get(svpm, vd) << "]: min of " << 0.9 * CGAL::approximate_sqrt(min_sq_dist) << " AND " << tolerance << std::endl; #endif - put(tol_pmap, vd, (std::min)(0.9 * CGAL::approximate_sqrt(min_sq_dist), tolerance)); + put(tol_pmap, vd, CGAL::min(0.9 * CGAL::approximate_sqrt(min_sq_dist), tolerance)); } } diff --git a/STL_Extension/include/CGAL/iterator.h b/STL_Extension/include/CGAL/iterator.h index 8d40cec8c38..08b31d48a65 100644 --- a/STL_Extension/include/CGAL/iterator.h +++ b/STL_Extension/include/CGAL/iterator.h @@ -669,10 +669,10 @@ class Join_input_iterator_1 public: typedef typename std::iterator_traits::iterator_category iterator_category; - typedef typename cpp11::result_of::type value_type; + typedef std::decay_t::type> value_type; typedef typename std::iterator_traits::difference_type difference_type; - typedef value_type* pointer; - typedef value_type& reference; + typedef value_type const* pointer; + typedef value_type const& reference; protected: I1 i1;