diff options
-rw-r--r-- | Eigen/src/Geometry/Quaternion.h | 9 | ||||
-rw-r--r-- | test/geo_quaternion.cpp | 5 |
2 files changed, 12 insertions, 2 deletions
diff --git a/Eigen/src/Geometry/Quaternion.h b/Eigen/src/Geometry/Quaternion.h index dd1217e5e..bebfca422 100644 --- a/Eigen/src/Geometry/Quaternion.h +++ b/Eigen/src/Geometry/Quaternion.h @@ -197,20 +197,25 @@ class QuaternionBase : public RotationBase<Derived, 3> #else template<typename NewScalarType> - EIGEN_DEVICE_FUNC inline + 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 + EIGEN_DEVICE_FUNC inline typename internal::enable_if<!internal::is_same<Scalar,NewScalarType>::value,Quaternion<NewScalarType> >::type cast() const { return Quaternion<NewScalarType>(coeffs().template cast<NewScalarType>()); } #endif + friend std::ostream& operator<<(std::ostream& s, const QuaternionBase<Derived>& q) { + s << q.x() << "i + " << q.y() << "j + " << q.z() << "k" << " + " << q.w(); + return s; + } + #ifdef EIGEN_QUATERNIONBASE_PLUGIN # include EIGEN_QUATERNIONBASE_PLUGIN #endif diff --git a/test/geo_quaternion.cpp b/test/geo_quaternion.cpp index 1da683c0e..b339a5f39 100644 --- a/test/geo_quaternion.cpp +++ b/test/geo_quaternion.cpp @@ -75,6 +75,11 @@ template<typename Scalar, int Options> void quaternion(void) q1.coeffs().setRandom(); VERIFY_IS_APPROX(q1.coeffs(), (q1*q2).coeffs()); + // Printing + std::ostringstream ss; + ss << q2; + VERIFY(ss.str() == "0i + 0j + 0k + 1"); + // concatenation q1 *= q2; |