mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-07 18:27:40 +08:00
Add unit tests for Rotation2D's inverse(), operator*, slerp, and fix regression wrt explicit ctor change
This commit is contained in:
parent
d04f23260d
commit
b4a9b3f496
@ -71,11 +71,11 @@ public:
|
|||||||
inline Scalar& angle() { return m_angle; }
|
inline Scalar& angle() { return m_angle; }
|
||||||
|
|
||||||
/** \returns the inverse rotation */
|
/** \returns the inverse rotation */
|
||||||
inline Rotation2D inverse() const { return -m_angle; }
|
inline Rotation2D inverse() const { return Rotation2D(-m_angle); }
|
||||||
|
|
||||||
/** Concatenates two rotations */
|
/** Concatenates two rotations */
|
||||||
inline Rotation2D operator*(const Rotation2D& other) const
|
inline Rotation2D operator*(const Rotation2D& other) const
|
||||||
{ return m_angle + other.m_angle; }
|
{ return Rotation2D(m_angle + other.m_angle); }
|
||||||
|
|
||||||
/** Concatenates two rotations */
|
/** Concatenates two rotations */
|
||||||
inline Rotation2D& operator*=(const Rotation2D& other)
|
inline Rotation2D& operator*=(const Rotation2D& other)
|
||||||
@ -93,7 +93,7 @@ public:
|
|||||||
* parameter \a t. It is in fact equivalent to a linear interpolation.
|
* parameter \a t. It is in fact equivalent to a linear interpolation.
|
||||||
*/
|
*/
|
||||||
inline Rotation2D slerp(const Scalar& t, const Rotation2D& other) const
|
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
|
/** \returns \c *this with scalar type casted to \a NewScalarType
|
||||||
*
|
*
|
||||||
|
@ -98,7 +98,7 @@ template<typename Scalar, int Mode, int Options> void transformations()
|
|||||||
Matrix3 matrot1, m;
|
Matrix3 matrot1, m;
|
||||||
|
|
||||||
Scalar a = internal::random<Scalar>(-Scalar(M_PI), Scalar(M_PI));
|
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(a, v0.normalized()) * v0);
|
||||||
VERIFY_IS_APPROX(-v0, AngleAxisx(Scalar(M_PI), v0.unitOrthogonal()) * 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>();
|
Rotation2D<double> r2d1d = r2d1.template cast<double>();
|
||||||
VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);
|
VERIFY_IS_APPROX(r2d1d.template cast<Scalar>(),r2d1);
|
||||||
|
|
||||||
t20 = Translation2(v20) * (Rotation2D<Scalar>(s0) * Eigen::Scaling(s0));
|
Rotation2D<Scalar> R0(s0), R1(s1);
|
||||||
t21 = Translation2(v20) * Rotation2D<Scalar>(s0) * Eigen::Scaling(s0);
|
|
||||||
|
t20 = Translation2(v20) * (R0 * Eigen::Scaling(s0));
|
||||||
|
t21 = Translation2(v20) * R0 * Eigen::Scaling(s0);
|
||||||
VERIFY_IS_APPROX(t20,t21);
|
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
|
// check basic features
|
||||||
{
|
{
|
||||||
Rotation2D<Scalar> r1; // default ctor
|
Rotation2D<Scalar> r1; // default ctor
|
||||||
|
Loading…
Reference in New Issue
Block a user