mirror of https://github.com/CGAL/cgal
Merge pull request #5585 from afabri/Kernel_23-rational_rotation-GF
Kernel_23: Remove local reference in rational_rotation.h
This commit is contained in:
commit
6d63fcc465
|
|
@ -27,13 +27,12 @@ template < class NT >
|
||||||
void
|
void
|
||||||
rational_rotation_approximation( const NT & dirx, // dir.x()
|
rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
const NT & diry, // dir.y()
|
const NT & diry, // dir.y()
|
||||||
NT & sin_num, // return
|
NT & sin, // numerator return
|
||||||
NT & cos_num, // return
|
NT & cos, // numerator return
|
||||||
NT & denom, // return
|
NT & den, // denominator return
|
||||||
const NT & eps_num, // quality_bound
|
const NT & eps_num, // quality_bound
|
||||||
const NT & eps_den )
|
const NT & eps_den )
|
||||||
{
|
{
|
||||||
|
|
||||||
const NT& n = eps_num;
|
const NT& n = eps_num;
|
||||||
const NT& d = eps_den;
|
const NT& d = eps_den;
|
||||||
const NT NT0 = NT(0) ;
|
const NT NT0 = NT(0) ;
|
||||||
|
|
@ -41,12 +40,9 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
CGAL_kernel_precondition( (dirx != NT0) || (diry != NT0));
|
CGAL_kernel_precondition( (dirx != NT0) || (diry != NT0));
|
||||||
CGAL_kernel_precondition( n > NT0 );
|
CGAL_kernel_precondition( n > NT0 );
|
||||||
CGAL_kernel_precondition( d > NT0 );
|
CGAL_kernel_precondition( d > NT0 );
|
||||||
NT & sin = sin_num;
|
NT dx = CGAL::abs(dirx);
|
||||||
NT & cos = cos_num;
|
NT dy = CGAL::abs(diry);
|
||||||
NT & den = denom;
|
NT sq_hypotenuse = square(dx) + square(dy);
|
||||||
NT dx = CGAL_NTS abs(dirx);
|
|
||||||
NT dy = CGAL_NTS abs(diry);
|
|
||||||
NT sq_hypotenuse = dx*dx + dy*dy;
|
|
||||||
NT common_part;
|
NT common_part;
|
||||||
NT diff_part;
|
NT diff_part;
|
||||||
NT rhs;
|
NT rhs;
|
||||||
|
|
@ -59,7 +55,7 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
}
|
}
|
||||||
// approximate sin = dy / sqrt(sq_hypotenuse)
|
// approximate sin = dy / sqrt(sq_hypotenuse)
|
||||||
// if ( dy / sqrt(sq_hypotenuse) < n/d )
|
// if ( dy / sqrt(sq_hypotenuse) < n/d )
|
||||||
if (dy * dy * d * d < sq_hypotenuse * n * n)
|
if (square(dy) * square(d) < sq_hypotenuse * square(n))
|
||||||
{
|
{
|
||||||
cos = NT1;
|
cos = NT1;
|
||||||
sin = NT0;
|
sin = NT0;
|
||||||
|
|
@ -79,7 +75,7 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
p = p0 + p1;
|
p = p0 + p1;
|
||||||
q = q0 + q1;
|
q = q0 + q1;
|
||||||
sin = NT(2)*p*q;
|
sin = NT(2)*p*q;
|
||||||
den = p*p + q*q;
|
den = square(p) + square(q);
|
||||||
|
|
||||||
// sanity check for approximation
|
// sanity check for approximation
|
||||||
// sin/den < dy/sqrt(hypotenuse) + n/d
|
// sin/den < dy/sqrt(hypotenuse) + n/d
|
||||||
|
|
@ -89,9 +85,9 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
// === (sin^2 d^2 + n^2 den^2)sq_hypotenuse - 2... < dy^2 d^2 den^2
|
// === (sin^2 d^2 + n^2 den^2)sq_hypotenuse - 2... < dy^2 d^2 den^2
|
||||||
// && (sin^2 d^2 + n^2 den^2)sq_hypotenuse + 2... > dy^2 d^2 den^2
|
// && (sin^2 d^2 + n^2 den^2)sq_hypotenuse + 2... > dy^2 d^2 den^2
|
||||||
|
|
||||||
common_part = (sin*sin*d*d + n*n*den*den)*sq_hypotenuse;
|
common_part = (square(sin) * square(d) + square(n) * square(den))*sq_hypotenuse;
|
||||||
diff_part = NT(2)*n*sin*d*den*sq_hypotenuse;
|
diff_part = NT(2)*n*sin*d*den*sq_hypotenuse;
|
||||||
rhs = dy*dy*d*d*den*den;
|
rhs = square(dy) * square(d) * square(den);
|
||||||
|
|
||||||
upper_ok = (common_part - diff_part < rhs);
|
upper_ok = (common_part - diff_part < rhs);
|
||||||
lower_ok = (common_part + diff_part > rhs);
|
lower_ok = (common_part + diff_part > rhs);
|
||||||
|
|
@ -106,7 +102,7 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
cos = q*q - p*p;
|
cos = square(q) - square(p);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -114,7 +110,7 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if ( dy/sqrt(sq_hypotenuse) < sin/den )
|
// if ( dy/sqrt(sq_hypotenuse) < sin/den )
|
||||||
if ( dy*dy*den*den < sin*sin*sq_hypotenuse )
|
if ( square(dy) * square(den) < square(sin) * sq_hypotenuse )
|
||||||
{
|
{
|
||||||
p1 = p;
|
p1 = p;
|
||||||
q1 = q;
|
q1 = q;
|
||||||
|
|
@ -130,24 +126,20 @@ rational_rotation_approximation( const NT & dirx, // dir.x()
|
||||||
dx = dirx;
|
dx = dirx;
|
||||||
dy = diry;
|
dy = diry;
|
||||||
|
|
||||||
if (CGAL_NTS abs(dy) > CGAL_NTS abs(dx) ) { std::swap (sin,cos); }
|
if (CGAL::abs(dy) > CGAL::abs(dx) ) { std::swap (sin,cos); }
|
||||||
|
|
||||||
if (dx < NT0) { cos = - cos; }
|
if (dx < NT0) { cos = - cos; }
|
||||||
|
|
||||||
if (dy < NT0) { sin = - sin; }
|
if (dy < NT0) { sin = - sin; }
|
||||||
|
|
||||||
sin_num = sin;
|
|
||||||
cos_num = cos;
|
|
||||||
denom = den;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template < class NT >
|
template < class NT >
|
||||||
void
|
void
|
||||||
rational_rotation_approximation( const double& angle,
|
rational_rotation_approximation( const double& angle,
|
||||||
NT & sin_num, // return
|
NT & isin, // numerator return
|
||||||
NT & cos_num, // return
|
NT & icos, // numerator return
|
||||||
NT & denom, // return
|
NT & iden, // denominator return
|
||||||
const NT & eps_num, // quality_bound
|
const NT & eps_num, // quality_bound
|
||||||
const NT & eps_den )
|
const NT & eps_den )
|
||||||
{
|
{
|
||||||
|
|
@ -158,16 +150,14 @@ rational_rotation_approximation( const double& angle,
|
||||||
const NT NT1 = NT(1) ;
|
const NT NT1 = NT(1) ;
|
||||||
CGAL_kernel_precondition( n > NT0 );
|
CGAL_kernel_precondition( n > NT0 );
|
||||||
CGAL_kernel_precondition( d > NT0 );
|
CGAL_kernel_precondition( d > NT0 );
|
||||||
NT& isin = sin_num;
|
|
||||||
NT& icos = cos_num;
|
|
||||||
NT& iden = denom;
|
|
||||||
double dsin = std::sin(angle);
|
double dsin = std::sin(angle);
|
||||||
double dcos = std::cos(angle);
|
double dcos = std::cos(angle);
|
||||||
double dn = CGAL::to_double(n);
|
double dn = CGAL::to_double(n);
|
||||||
double dd = CGAL::to_double(d);
|
double dd = CGAL::to_double(d);
|
||||||
double eps = dn / dd;
|
double eps = dn / dd;
|
||||||
dsin = CGAL_NTS abs( dsin);
|
dsin = CGAL::abs( dsin);
|
||||||
dcos = CGAL_NTS abs( dcos);
|
dcos = CGAL::abs( dcos);
|
||||||
NT common_part;
|
NT common_part;
|
||||||
NT diff_part;
|
NT diff_part;
|
||||||
NT os;
|
NT os;
|
||||||
|
|
@ -200,7 +190,7 @@ rational_rotation_approximation( const double& angle,
|
||||||
p = p0 + p1;
|
p = p0 + p1;
|
||||||
q = q0 + q1;
|
q = q0 + q1;
|
||||||
isin = NT(2)*p*q;
|
isin = NT(2)*p*q;
|
||||||
iden = p*p + q*q;
|
iden = square(p) + square(q);
|
||||||
|
|
||||||
// XXX sanity check for approximation
|
// XXX sanity check for approximation
|
||||||
// sin/den < dsin + n/d
|
// sin/den < dsin + n/d
|
||||||
|
|
@ -224,7 +214,7 @@ rational_rotation_approximation( const double& angle,
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// {
|
// {
|
||||||
icos = q*q - p*p;
|
icos = square(q) - square(p);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
@ -253,9 +243,6 @@ rational_rotation_approximation( const double& angle,
|
||||||
if (dcos < 0.0) { icos = - icos; }
|
if (dcos < 0.0) { icos = - icos; }
|
||||||
if (dsin < 0.0) { isin = - isin; }
|
if (dsin < 0.0) { isin = - isin; }
|
||||||
|
|
||||||
sin_num = isin;
|
|
||||||
cos_num = icos;
|
|
||||||
denom = iden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} //namespace CGAL
|
} //namespace CGAL
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue