- remove most of the metaprogramming kung fu in MathFunctions.h (only keep functions that differs from the std)
- remove the overloads for array expression that were in the std namespace
This commit is contained in:
Gael Guennebaud
2012-11-06 15:25:50 +01:00
parent 959ef37006
commit a76fbbf397
88 changed files with 496 additions and 468 deletions

View File

@@ -248,14 +248,14 @@ EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
*/
template<typename Derived>
inline NonInteger exteriorDistance(const MatrixBase<Derived>& p) const
{ return internal::sqrt(NonInteger(squaredExteriorDistance(p))); }
{ using std::sqrt; return sqrt(NonInteger(squaredExteriorDistance(p))); }
/** \returns the distance between the boxes \a b and \c *this,
* and zero if the boxes intersect.
* \sa squaredExteriorDistance()
*/
inline NonInteger exteriorDistance(const AlignedBox& b) const
{ return internal::sqrt(NonInteger(squaredExteriorDistance(b))); }
{ using std::sqrt; return sqrt(NonInteger(squaredExteriorDistance(b))); }
/** \returns \c *this with scalar type casted to \a NewScalarType
*

View File

@@ -161,6 +161,7 @@ AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const QuaternionBase<QuatDerived
using std::acos;
using std::min;
using std::max;
using std::sqrt;
Scalar n2 = q.vec().squaredNorm();
if (n2 < NumTraits<Scalar>::dummy_precision()*NumTraits<Scalar>::dummy_precision())
{
@@ -170,7 +171,7 @@ AngleAxis<Scalar>& AngleAxis<Scalar>::operator=(const QuaternionBase<QuatDerived
else
{
m_angle = Scalar(2)*acos((min)((max)(Scalar(-1),q.w()),Scalar(1)));
m_axis = q.vec() / internal::sqrt(n2);
m_axis = q.vec() / sqrt(n2);
}
return *this;
}
@@ -202,9 +203,11 @@ template<typename Scalar>
typename AngleAxis<Scalar>::Matrix3
AngleAxis<Scalar>::toRotationMatrix(void) const
{
using std::sin;
using std::cos;
Matrix3 res;
Vector3 sin_axis = internal::sin(m_angle) * m_axis;
Scalar c = internal::cos(m_angle);
Vector3 sin_axis = sin(m_angle) * m_axis;
Scalar c = cos(m_angle);
Vector3 cos1_axis = (Scalar(1)-c) * m_axis;
Scalar tmp;

View File

@@ -32,6 +32,7 @@ template<typename Derived>
inline Matrix<typename MatrixBase<Derived>::Scalar,3,1>
MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
{
using std::atan2;
/* Implemented from Graphics Gems IV */
EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(Derived,3,3)
@@ -47,31 +48,31 @@ MatrixBase<Derived>::eulerAngles(Index a0, Index a1, Index a2) const
if (a0==a2)
{
Scalar s = Vector2(coeff(j,i) , coeff(k,i)).norm();
res[1] = internal::atan2(s, coeff(i,i));
res[1] = atan2(s, coeff(i,i));
if (s > epsilon)
{
res[0] = internal::atan2(coeff(j,i), coeff(k,i));
res[2] = internal::atan2(coeff(i,j),-coeff(i,k));
res[0] = atan2(coeff(j,i), coeff(k,i));
res[2] = atan2(coeff(i,j),-coeff(i,k));
}
else
{
res[0] = Scalar(0);
res[2] = (coeff(i,i)>0?1:-1)*internal::atan2(-coeff(k,j), coeff(j,j));
res[2] = (coeff(i,i)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j));
}
}
else
{
Scalar c = Vector2(coeff(i,i) , coeff(i,j)).norm();
res[1] = internal::atan2(-coeff(i,k), c);
res[1] = atan2(-coeff(i,k), c);
if (c > epsilon)
{
res[0] = internal::atan2(coeff(j,k), coeff(k,k));
res[2] = internal::atan2(coeff(i,j), coeff(i,i));
res[0] = atan2(coeff(j,k), coeff(k,k));
res[2] = atan2(coeff(i,j), coeff(i,i));
}
else
{
res[0] = Scalar(0);
res[2] = (coeff(i,k)>0?1:-1)*internal::atan2(-coeff(k,j), coeff(j,j));
res[2] = (coeff(i,k)>0?1:-1)*atan2(-coeff(k,j), coeff(j,j));
}
}
if (!odd)

View File

@@ -135,7 +135,7 @@ public:
/** \returns the absolute distance between the plane \c *this and a point \a p.
* \sa signedDistance()
*/
inline Scalar absDistance(const VectorType& p) const { return internal::abs(signedDistance(p)); }
inline Scalar absDistance(const VectorType& p) const { using std::abs; return abs(signedDistance(p)); }
/** \returns the projection of a point \a p onto the plane \c *this.
*/
@@ -178,13 +178,14 @@ public:
*/
VectorType intersection(const Hyperplane& other) const
{
using std::abs;
EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0);
// since the line equations ax+by=c are normalized with a^2+b^2=1, the following tests
// whether the two lines are approximately parallel.
if(internal::isMuchSmallerThan(det, Scalar(1)))
{ // special case where the two lines are approximately parallel. Pick any point on the first line.
if(internal::abs(coeffs().coeff(1))>internal::abs(coeffs().coeff(0)))
if(abs(coeffs().coeff(1))>abs(coeffs().coeff(0)))
return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0));
else
return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0));

View File

@@ -87,7 +87,7 @@ public:
/** \returns the distance of a point \a p to its projection onto the line \c *this.
* \sa squaredDistance()
*/
RealScalar distance(const VectorType& p) const { return internal::sqrt(squaredDistance(p)); }
RealScalar distance(const VectorType& p) const { using std::sqrt; return sqrt(squaredDistance(p)); }
/** \returns the projection of a point \a p onto the line \c *this. */
VectorType projection(const VectorType& p) const

View File

@@ -505,9 +505,11 @@ EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const Quaternion
template<class Derived>
EIGEN_STRONG_INLINE Derived& QuaternionBase<Derived>::operator=(const AngleAxisType& aa)
{
using std::cos;
using std::sin;
Scalar ha = Scalar(0.5)*aa.angle(); // Scalar(0.5) to suppress precision loss warnings
this->w() = internal::cos(ha);
this->vec() = internal::sin(ha) * aa.axis();
this->w() = cos(ha);
this->vec() = sin(ha) * aa.axis();
return derived();
}
@@ -581,6 +583,7 @@ template<typename Derived1, typename Derived2>
inline Derived& QuaternionBase<Derived>::setFromTwoVectors(const MatrixBase<Derived1>& a, const MatrixBase<Derived2>& b)
{
using std::max;
using std::sqrt;
Vector3 v0 = a.normalized();
Vector3 v1 = b.normalized();
Scalar c = v1.dot(v0);
@@ -601,12 +604,12 @@ inline Derived& QuaternionBase<Derived>::setFromTwoVectors(const MatrixBase<Deri
Vector3 axis = svd.matrixV().col(2);
Scalar w2 = (Scalar(1)+c)*Scalar(0.5);
this->w() = internal::sqrt(w2);
this->vec() = axis * internal::sqrt(Scalar(1) - w2);
this->w() = sqrt(w2);
this->vec() = axis * sqrt(Scalar(1) - w2);
return derived();
}
Vector3 axis = v0.cross(v1);
Scalar s = internal::sqrt((Scalar(1)+c)*Scalar(2));
Scalar s = sqrt((Scalar(1)+c)*Scalar(2));
Scalar invs = Scalar(1)/s;
this->vec() = axis * invs;
this->w() = s * Scalar(0.5);
@@ -677,7 +680,8 @@ inline typename internal::traits<Derived>::Scalar
QuaternionBase<Derived>::angularDistance(const QuaternionBase<OtherDerived>& other) const
{
using std::acos;
double d = internal::abs(this->dot(other));
using std::abs;
double d = abs(this->dot(other));
if (d>=1.0)
return Scalar(0);
return static_cast<Scalar>(2 * acos(d));
@@ -692,9 +696,11 @@ Quaternion<typename internal::traits<Derived>::Scalar>
QuaternionBase<Derived>::slerp(Scalar t, const QuaternionBase<OtherDerived>& other) const
{
using std::acos;
using std::sin;
using std::abs;
static const Scalar one = Scalar(1) - NumTraits<Scalar>::epsilon();
Scalar d = this->dot(other);
Scalar absD = internal::abs(d);
Scalar absD = abs(d);
Scalar scale0;
Scalar scale1;
@@ -708,10 +714,10 @@ QuaternionBase<Derived>::slerp(Scalar t, const QuaternionBase<OtherDerived>& oth
{
// theta is the angle between the 2 quaternions
Scalar theta = acos(absD);
Scalar sinTheta = internal::sin(theta);
Scalar sinTheta = sin(theta);
scale0 = internal::sin( ( Scalar(1) - t ) * theta) / sinTheta;
scale1 = internal::sin( ( t * theta) ) / sinTheta;
scale0 = sin( ( Scalar(1) - t ) * theta) / sinTheta;
scale1 = sin( ( t * theta) ) / sinTheta;
}
if(d<0) scale1 = -scale1;
@@ -728,6 +734,7 @@ struct quaternionbase_assign_impl<Other,3,3>
typedef DenseIndex Index;
template<class Derived> static inline void run(QuaternionBase<Derived>& q, const Other& mat)
{
using std::sqrt;
// This algorithm comes from "Quaternion Calculus and Fast Animation",
// Ken Shoemake, 1987 SIGGRAPH course notes
Scalar t = mat.trace();

View File

@@ -133,8 +133,9 @@ template<typename Scalar>
template<typename Derived>
Rotation2D<Scalar>& Rotation2D<Scalar>::fromRotationMatrix(const MatrixBase<Derived>& mat)
{
using std::atan2;
EIGEN_STATIC_ASSERT(Derived::RowsAtCompileTime==2 && Derived::ColsAtCompileTime==2,YOU_MADE_A_PROGRAMMING_MISTAKE)
m_angle = internal::atan2(mat.coeff(1,0), mat.coeff(0,0));
m_angle = atan2(mat.coeff(1,0), mat.coeff(0,0));
return *this;
}
@@ -144,8 +145,10 @@ template<typename Scalar>
typename Rotation2D<Scalar>::Matrix2
Rotation2D<Scalar>::toRotationMatrix(void) const
{
Scalar sinA = internal::sin(m_angle);
Scalar cosA = internal::cos(m_angle);
using std::sin;
using std::cos;
Scalar sinA = sin(m_angle);
Scalar cosA = cos(m_angle);
return (Matrix2() << cosA, -sinA, sinA, cosA).finished();
}