Merge pull request #3943 from mglisse/Number_types-expression_templates-glisse

Misc fixes for expression templates
This commit is contained in:
Laurent Rineau 2019-05-23 08:50:17 +02:00
commit 5c2df203b4
13 changed files with 82 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}).
// 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<FT>(r[j]*r[j+1] + scalar_product_2(s[j], s[j+1]), 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].
// 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/number_utils.h>
#include <utility>
#include <vector>
@ -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()) &&

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.
//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<RT>(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;

View File

@ -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)

View File

@ -26,6 +26,7 @@
#include <CGAL/number_utils.h>
#include <CGAL/predicates/sign_of_determinant.h>
namespace CGAL {
@ -78,11 +79,11 @@ side_of_plane_centered_sphereC3(const RT &ax, const RT &ay, const RT &az,
// - tranlation of p to the origin.
// - separate 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<RT>(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 +101,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<RT>(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<RT>(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<RT>(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<RT>(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 +148,10 @@ side_of_plane_centered_sphereC3(const RT &ax, const RT &ay, const RT &az,
// - tranlation of p to the origin.
// - separate 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<RT>(ax-px, ay-py, az-pz,
nx, ny, nz,
qx-px, qy-py,qz-pz,
rx-px, ry-py,rz-pz);
}
} //namespace CGAL

View File

@ -4,7 +4,9 @@ Filtered_kernel
Hash_map
Installation
Interpolation
Interval_support
Kernel_23
Modular_arithmetic
Number_types
Polygon
Profiling_tools

View File

@ -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<NT1, NT2, NT3>;
typename Root_of_traits<NT>::Make_root_of_2 make_root_of_2;
return make_root_of_2(a,b,c);
}

View File

@ -651,6 +651,37 @@ CGAL::Comparison_result
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
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
Sqrt_extension<NT,ROOT,ACDE_TAG,FP_TAG> min BOOST_PREVENT_MACRO_SUBSTITUTION(

View File

@ -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))

View File

@ -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;
}

View File

@ -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<FT>( p.x()-1, 0 ) : p.x()),
(p.y() > FT(0.9375) ? CGAL::max<FT>( 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());

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 "
<< 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<FT>(0.9 * CGAL::approximate_sqrt(min_sq_dist), tolerance));
}
}

View File

@ -669,10 +669,10 @@ class Join_input_iterator_1
public:
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 value_type* pointer;
typedef value_type& reference;
typedef value_type const* pointer;
typedef value_type const& reference;
protected:
I1 i1;