Add unit tests for Rotation2D's inverse(), operator*, slerp, and fix regression wrt explicit ctor change

This commit is contained in:
Gael Guennebaud 2014-10-20 11:04:32 +02:00
parent d04f23260d
commit b4a9b3f496
2 changed files with 17 additions and 6 deletions

View File

@ -71,11 +71,11 @@ public:
inline Scalar& angle() { return m_angle; }
/** \returns the inverse rotation */
inline Rotation2D inverse() const { return -m_angle; }
inline Rotation2D inverse() const { return Rotation2D(-m_angle); }
/** Concatenates two rotations */
inline Rotation2D operator*(const Rotation2D& other) const
{ return m_angle + other.m_angle; }
{ return Rotation2D(m_angle + other.m_angle); }
/** Concatenates two rotations */
inline Rotation2D& operator*=(const Rotation2D& other)
@ -93,7 +93,7 @@ public:
* parameter \a t. It is in fact equivalent to a linear interpolation.
*/
inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const
{ return m_angle * (1-t) + other.angle() * t; }
{ return Rotation2D(m_angle * (1-t) + other.angle() * t); }
/** \returns \c *this with scalar type casted to \a NewScalarType
*

View File

@ -98,7 +98,7 @@ template<typename Scalar, int Mode, int Options> void transformations()
Matrix3 matrot1, m;
Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
Scalar s0 = internal::random<Scalar>();
Scalar s0 = internal::random<Scalar>(), s1 = internal::random<Scalar>();
VERIFY_IS_APPROX(v0, AngleAxisx(a, v0.normalized()) * v0);
VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(M_PI), v0.unitOrthogonal()) * v0);
@ -394,10 +394,21 @@ template<typename Scalar, int Mode, int Options> void transformations()
Rotation2D<double> r2d1d = r2d1.template cast<double>();
VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);
t20 = Translation2(v20) * (Rotation2D<Scalar>(s0) * Eigen::Scaling(s0));
t21 = Translation2(v20) * Rotation2D<Scalar>(s0) * Eigen::Scaling(s0);
Rotation2D<Scalar> R0(s0), R1(s1);
t20 = Translation2(v20) * (R0 * Eigen::Scaling(s0));
t21 = Translation2(v20) * R0 * Eigen::Scaling(s0);
VERIFY_IS_APPROX(t20,t21);
t20 = Translation2(v20) * (R0 * R0.inverse() * Eigen::Scaling(s0));
t21 = Translation2(v20) * Eigen::Scaling(s0);
VERIFY_IS_APPROX(t20,t21);
VERIFY_IS_APPROX(s0, (R0.slerp(0, R1)).angle());
VERIFY_IS_APPROX(s1, (R0.slerp(1, R1)).angle());
VERIFY_IS_APPROX(s0, (R0.slerp(0.5, R0)).angle());
VERIFY_IS_APPROX(Scalar(0), (R0.slerp(0.5, R0.inverse())).angle());
// check basic features
{
Rotation2D<Scalar> r1; // default ctor