quaternion_print.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00013 #ifndef quaternion_print_h
00014 #define quaternion_print_h
00015
00016 #include <iostream>
00017
00018 namespace cml {
00019
00020
00021
00022
00023 #if defined(CML_COMPLEX_QUATERNION_OUTPUT)
00024
00025 template<typename E, class AT, class CT> std::ostream&
00026 operator<<(std::ostream& os, const cml::quaternion<E,AT,scalar_first,CT>& q)
00027 {
00028 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]);
00029 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "i";
00030 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "j";
00031 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]) << "k";
00032 return os;
00033 }
00034
00035 template<typename E, class AT, class CT> std::ostream&
00036 operator<<(std::ostream& os, const cml::quaternion<E,AT,vector_first,CT>& q)
00037 {
00038 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]) << "i";
00039 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "j";
00040 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "k";
00041 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]);
00042 return os;
00043 }
00044
00045 #else
00046
00048 template<typename E, class AT, class OT, typename CT> std::ostream&
00049 operator<<(std::ostream& os, const cml::quaternion<E,AT,OT,CT>& q)
00050 {
00051 os << "[";
00052 for (size_t i = 0; i < 4; ++i) {
00053 os << " " << q[i];
00054 }
00055 os << " ]";
00056 return os;
00057 }
00058
00059 #endif
00060
00062 template< class XprT > inline std::ostream&
00063 operator<<(std::ostream& os, const et::QuaternionXpr<XprT>& q)
00064 {
00065 typedef typename et::QuaternionXpr<XprT>::result_type quaternion_type;
00066
00067 os << quaternion_type(q);
00068
00069
00070
00071
00072 return os;
00073 }
00074
00075 }
00076
00077 #endif
00078
00079
00080