Misc fixes for expression templates

This commit is contained in:
Marc Glisse 2019-05-17 19:48:41 +02:00
parent 934544dbde
commit a676b75ca0
12 changed files with 79 additions and 101 deletions

View File

@ -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}). // 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]. // Vector s_i from [1] corresponds to that one with the name d_i in [2].
for(int j = 0; j < n-1; ++j) 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[j] = CGAL::max<FT>(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]), FT(0)); P[n-1] = CGAL::max<FT>(r[n-1]*r[0] + scalar_product_2(s[n-1], s[0]), 0);
// Compute mean value weights using the formula (16) from [2]. // 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. // Since the formula (16) always gives positive values, we have to add a proper sign to all the weight functions.

View File

@ -29,6 +29,7 @@
#include <CGAL/Circular_kernel_3/Intersection_traits.h> #include <CGAL/Circular_kernel_3/Intersection_traits.h>
#include <CGAL/number_utils.h>
#include <utility> #include <utility>
#include <vector> #include <vector>
@ -140,10 +141,10 @@ namespace CGAL {
{ {
// Should we compare anyway even if they are degenerated? // Should we compare anyway even if they are degenerated?
CGAL_kernel_assertion(!(p1.is_degenerate() || p2.is_degenerate())); CGAL_kernel_assertion(!(p1.is_degenerate() || p2.is_degenerate()));
if(is_zero(p1.a())) { if(CGAL::is_zero(p1.a())) {
if(!is_zero(p2.a())) return false; if(!CGAL::is_zero(p2.a())) return false;
if(is_zero(p1.b())) { if(CGAL::is_zero(p1.b())) {
if(!is_zero(p2.b())) return false; if(!CGAL::is_zero(p2.b())) return false;
return p1.c() * p2.d() == p1.d() * p2.c(); return p1.c() * p2.d() == p1.d() * p2.c();
} }
return (p2.c() * p1.b() == p1.c() * p2.b()) && return (p2.c() * p1.b() == p1.c() * p2.b()) &&

View File

@ -83,11 +83,11 @@ plane_centered_circumcenterC3(const RT &ax, const RT &ay, const RT &az,
//precondition: p,q,r aren't collinear. //precondition: p,q,r aren't collinear.
//method: //method:
// - tranlation of p to the origin. // - tranlation of p to the origin.
plane_centered_circumcenter_translateC3(ax-px, ay-py, az-pz, plane_centered_circumcenter_translateC3<RT>(ax-px, ay-py, az-pz,
nx, ny, nz, nx, ny, nz,
qx-px, qy-py,qz-pz, qx-px, qy-py,qz-pz,
rx-px, ry-py,rz-pz, rx-px, ry-py,rz-pz,
x, y, z); x, y, z);
x+=px; x+=px;
y+=py; y+=py;
z+=pz; z+=pz;

View File

@ -121,7 +121,7 @@ natural_neighbors_2(const Dt& dt,
*out++ = std::make_pair(v1,coef1); *out++ = std::make_pair(v1,coef1);
*out++ = std::make_pair(v2,coef2); *out++ = std::make_pair(v2,coef2);
return make_triple(out, coef1+coef2, true); return { out, coef1+coef2, true };
} }
if (lt == Dt::VERTEX) if (lt == Dt::VERTEX)

View File

@ -78,11 +78,11 @@ side_of_plane_centered_sphereC3(const RT &ax, const RT &ay, const RT &az,
// - tranlation of p to the origin. // - tranlation of p to the origin.
// - seperate computation of det and norm of the expression // - seperate computation of det and norm of the expression
return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, return side_of_plane_centered_sphere_translateC3<RT>(ax-px, ay-py, az-pz,
nx, ny, nz, nx, ny, nz,
qx-px, qy-py,qz-pz, qx-px, qy-py,qz-pz,
rx-px, ry-py,rz-pz, rx-px, ry-py,rz-pz,
tx-px, ty-py,tz-pz); tx-px, ty-py,tz-pz);
} }
template < class RT> template < class RT>
@ -100,25 +100,25 @@ side_of_plane_centered_sphere_translateC3(
RT na =nx*ax + ny*ay + nz*az; RT na =nx*ax + ny*ay + nz*az;
na *= RT(2.0); na *= RT(2.0);
Sign num = sign_of_determinant(qx, qy, qz, q2, Sign num = sign_of_determinant<RT>(qx, qy, qz, q2,
ny, -nx, RT(0), RT(0), ny, -nx, 0, 0,
nx, ny, nz, na, nx, ny, nz, na,
rx, ry, rz, r2); rx, ry, rz, r2);
//denumerator: //denumerator:
Sign den = sign_of_determinant(nx,ny,nz, Sign den = sign_of_determinant<RT>(nx,ny,nz,
ny,-nx, RT(0), ny,-nx, 0,
qx,qy,qz); qx,qy,qz);
if (den==ZERO) { if (den==ZERO) {
// bad choice: (ny,-nx,0) is coplanar with n,q. // bad choice: (ny,-nx,0) is coplanar with n,q.
// by precondition: q and n may not be collinear // by precondition: q and n may not be collinear
// => the cross product q*n is orthogonal to q, n and not coplanar // => the cross product q*n is orthogonal to q, n and not coplanar
num = sign_of_determinant(qx, qy, qz, q2, num = sign_of_determinant<RT>(qx, qy, qz, q2,
ny*qz-nz*qy, nz*qx-nx*qz,nx*qy-ny*qx, RT(0), ny*qz-nz*qy, nz*qx-nx*qz,nx*qy-ny*qx, 0,
nx, ny, nz, na, nx, ny, nz, na,
rx, ry, rz, r2); rx, ry, rz, r2);
den = sign_of_determinant(nx,ny,nz, den = sign_of_determinant<RT>(nx,ny,nz,
ny*qz-nz*qy, nz*qx - nx*qz,nx*qy-ny*qx, ny*qz-nz*qy, nz*qx - nx*qz,nx*qy-ny*qx,
qx,qy,qz); qx,qy,qz);
} }
CGAL_assertion(den != ZERO); CGAL_assertion(den != ZERO);
return den * num; 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. // - tranlation of p to the origin.
// - seperate computation of det and nom of the expression // - seperate computation of det and nom of the expression
return side_of_plane_centered_sphere_translateC3(ax-px, ay-py, az-pz, return side_of_plane_centered_sphere_translateC3<RT>(ax-px, ay-py, az-pz,
nx, ny, nz, nx, ny, nz,
qx-px, qy-py,qz-pz, qx-px, qy-py,qz-pz,
rx-px, ry-py,rz-pz); rx-px, ry-py,rz-pz);
} }
} //namespace CGAL } //namespace CGAL

View File

@ -33,11 +33,12 @@ namespace CGAL {
template < typename NT > template < typename NT >
struct Root_of_traits; struct Root_of_traits;
template < class NT > template < class NT1, class NT2, class NT3 >
inline inline
typename Root_of_traits< NT >::Root_of_2 auto
make_root_of_2(const NT &a, const NT &b, const NT &c) make_root_of_2(const NT1 &a, const NT2 &b, const NT3 &c)
{ {
using NT = std::common_type_t<NT1, NT2, NT3>;
typename Root_of_traits<NT>::Make_root_of_2 make_root_of_2; typename Root_of_traits<NT>::Make_root_of_2 make_root_of_2;
return make_root_of_2(a,b,c); return make_root_of_2(a,b,c);
} }

View File

@ -651,6 +651,37 @@ CGAL::Comparison_result
return (EQUAL); return (EQUAL);
} }
private:
template <class A,class B,class C> static bool
is_equal (const Sqrt_extension<A,B,Tag_false,C>& p1, const Sqrt_extension<A,B,Tag_false,C>& p2)
{ return (p1-p2).is_zero(); }
template <class A,class B,class C> static bool
is_equal (const Sqrt_extension<A,B,Tag_true,C>& p1, const Sqrt_extension<A,B,Tag_true,C>& 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<NT,ROOT,ACDE_TAG,FP_TAG>& p){
// BINARY // BINARY
template <class NT,class ROOT,class FP_TAG> bool
operator == (const Sqrt_extension<NT,ROOT,Tag_false,FP_TAG>& p1, const Sqrt_extension<NT,ROOT,Tag_false,FP_TAG>& p2)
{ return (p1-p2).is_zero(); }
template <class NT,class ROOT,class FP_TAG> bool
operator == (const Sqrt_extension<NT,ROOT,Tag_true,FP_TAG>& p1, const Sqrt_extension<NT,ROOT,Tag_true,FP_TAG>& p2)
{ return ( p1.compare(p2) == CGAL::ZERO ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool
operator < (const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p1, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p2)
{ return ( p1.compare(p2) == CGAL::SMALLER ); }
// NT
// righthand side
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator ==
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, const NT& num)
{ return (p-num).is_zero();}
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator <
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, const NT& num)
{ return ( p.compare(num) == CGAL::SMALLER ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator >
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, const NT& num)
{ return ( p.compare(num) == CGAL::LARGER ); }
// lefthand side
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator ==
(const NT& num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p == num );}
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator <
(const NT& num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p.compare(num) == CGAL::LARGER ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator >
(const NT& num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p.compare(num) == CGAL::SMALLER ); }
//CGAL_int(NT)
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator ==
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, CGAL_int(NT) num)
{ return (p-num).is_zero();}
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator <
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, CGAL_int(NT) num)
{ return ( p.compare(num) == CGAL::SMALLER ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator >
(const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p, CGAL_int(NT) num)
{ return ( p.compare(num) == CGAL::LARGER ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator ==
(CGAL_int(NT) num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p == num );}
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator <
(CGAL_int(NT) num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p.compare(num) == CGAL::LARGER ); }
template <class NT,class ROOT,class ACDE_TAG,class FP_TAG> bool operator >
(CGAL_int(NT) num, const Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG>& p)
{ return ( p.compare(num) == CGAL::SMALLER ); }
template<class NT, class ROOT,class ACDE_TAG,class FP_TAG> inline template<class NT, class ROOT,class ACDE_TAG,class FP_TAG> inline
Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> min BOOST_PREVENT_MACRO_SUBSTITUTION( Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> min BOOST_PREVENT_MACRO_SUBSTITUTION(

View File

@ -1075,7 +1075,7 @@ public:
return false; 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(Dac) )
{ {
if ( !is_infinity(Dbd)) if ( !is_infinity(Dbd))

View File

@ -686,7 +686,7 @@ public:
{ {
if (m_tolerance == (FT)(-1.)) if (m_tolerance == (FT)(-1.))
return false; 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; return cost > m_tolerance;
} }

View File

@ -697,8 +697,8 @@ static const int O[216][4] = {
vertices[9*i+3*j+k] = _tds.create_vertex(); vertices[9*i+3*j+k] = _tds.create_vertex();
Point p(k*(1.0/3.0) + i*(1.0/6.0), 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) ); 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 = Point((p.x() > FT(0.9375) ? CGAL::max<FT>( p.x()-1, 0 ) : p.x()),
(p.y() > FT(0.9375) ? (std::max)( p.y()-1, FT(0) ) : p.y()), p.z()); (p.y() > FT(0.9375) ? CGAL::max<FT>( p.y()-1, 0 ) : p.y()), p.z());
p = Point((domain().xmax()-domain().xmin())*p.x(), p = Point((domain().xmax()-domain().xmin())*p.x(),
(domain().xmax()-domain().xmin())*p.y(), (domain().xmax()-domain().xmin())*p.y(),
(domain().xmax()-domain().xmin())*p.z()); (domain().xmax()-domain().xmin())*p.z());

View File

@ -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 " std::cout << "tolerance at vd: " /*<< vd */ << " [" << get(svpm, vd) << "]: min of "
<< 0.9 * CGAL::approximate_sqrt(min_sq_dist) << " AND " << tolerance << std::endl; << 0.9 * CGAL::approximate_sqrt(min_sq_dist) << " AND " << tolerance << std::endl;
#endif #endif
put(tol_pmap, vd, (std::min)(0.9 * CGAL::approximate_sqrt(min_sq_dist), tolerance)); put(tol_pmap, vd, CGAL::min<FT>(0.9 * CGAL::approximate_sqrt(min_sq_dist), tolerance));
} }
} }

View File

@ -669,10 +669,10 @@ class Join_input_iterator_1
public: public:
typedef typename std::iterator_traits<I1>::iterator_category iterator_category; typedef typename std::iterator_traits<I1>::iterator_category iterator_category;
typedef typename cpp11::result_of<Op(arg_type)>::type value_type; typedef std::decay_t<typename cpp11::result_of<Op(arg_type)>::type> value_type;
typedef typename std::iterator_traits<I1>::difference_type difference_type; typedef typename std::iterator_traits<I1>::difference_type difference_type;
typedef value_type* pointer; typedef value_type const* pointer;
typedef value_type& reference; typedef value_type const& reference;
protected: protected:
I1 i1; I1 i1;