diff --git a/Eigen/src/Geometry/Rotation2D.h b/Eigen/src/Geometry/Rotation2D.h index 776c36144..4feb3d4d2 100644 --- a/Eigen/src/Geometry/Rotation2D.h +++ b/Eigen/src/Geometry/Rotation2D.h @@ -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 * diff --git a/test/geo_transformations.cpp b/test/geo_transformations.cpp index 1768d7b8a..e189217eb 100644 --- a/test/geo_transformations.cpp +++ b/test/geo_transformations.cpp @@ -98,7 +98,7 @@ template void transformations() Matrix3 matrot1, m; Scalar a = internal::random(-Scalar(M_PI), Scalar(M_PI)); - Scalar s0 = internal::random(); + Scalar s0 = internal::random(), s1 = internal::random(); 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 void transformations() Rotation2D r2d1d = r2d1.template cast(); VERIFY_IS_APPROX(r2d1d.template cast(),r2d1); - t20 = Translation2(v20) * (Rotation2D(s0) * Eigen::Scaling(s0)); - t21 = Translation2(v20) * Rotation2D(s0) * Eigen::Scaling(s0); + Rotation2D 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 r1; // default ctor