diff options
-rw-r--r-- | Eigen/src/Geometry/Quaternion.h | 19 | ||||
-rw-r--r-- | test/geo_quaternion.cpp | 8 |
2 files changed, 25 insertions, 2 deletions
diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index faea62f17..73b28ae34 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -169,16 +169,31 @@ class QuaternionBase : public RotationBase<Derived, 3> /** return the result vector of \a v through the rotation*/ EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Vector3 _transformVector(const Vector3& v) const; + #ifdef EIGEN_PARSED_BY_DOXYGEN /** \returns \c *this with scalar type casted to \a NewScalarType * * Note that if \a NewScalarType is equal to the current scalar type of \c *this * then this function smartly returns a const reference to \c *this. */ template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type cast() const + EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type cast() const; + + #else + + template<typename NewScalarType> + EIGEN_DEVICE_FUNC inline + typename internal::enable_if<internal::is_same<Scalar,NewScalarType>::value,const Derived&>::type cast() const + { + return derived(); + } + + template<typename NewScalarType> + EIGEN_DEVICE_FUNC inline + typename internal::enable_if<!internal::is_same<Scalar,NewScalarType>::value,Quaternion<NewScalarType> >::type cast() const { - return typename internal::cast_return_type<Derived,Quaternion<NewScalarType> >::type(derived()); + return Quaternion<NewScalarType>(coeffs().template cast<NewScalarType>()); } + #endif #ifdef EIGEN_QUATERNIONBASE_PLUGIN # include EIGEN_QUATERNIONBASE_PLUGIN diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp index 27219db10..1da683c0e 100644 --- a/test/geo_quaternion.cpp +++ b/test/geo_quaternion.cpp @@ -245,6 +245,14 @@ template<typename Scalar> void mapQuaternion(void){ // is used to determine whether we can return a coeff by reference or not, which is not enough for Map<const ...>. //const MCQuaternionUA& cmcq3(mcq3); //VERIFY( &cmcq3.x() == &mcq3.x() ); + + // test cast + { + Quaternion<float> q1f = mq1.template cast<float>(); + VERIFY_IS_APPROX(q1f.template cast<Scalar>(),mq1); + Quaternion<double> q1d = mq1.template cast<double>(); + VERIFY_IS_APPROX(q1d.template cast<Scalar>(),mq1); + } } template<typename Scalar> void quaternionAlignment(void){ |