X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fcml%2Fquaternion%2Fquaternion_print.h;fp=src%2Fmoof%2Fcml%2Fquaternion%2Fquaternion_print.h;h=483dfc4cefec591321ddcbbad3df2773df9f8118;hp=0000000000000000000000000000000000000000;hb=831f04d4bc19a390415ac0bbac4331c7a65509bc;hpb=299af4f2047e767e5d79501c26444473bda64c64 diff --git a/src/moof/cml/quaternion/quaternion_print.h b/src/moof/cml/quaternion/quaternion_print.h new file mode 100644 index 0000000..483dfc4 --- /dev/null +++ b/src/moof/cml/quaternion/quaternion_print.h @@ -0,0 +1,90 @@ +/* -*- C++ -*- ------------------------------------------------------------ + +Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/ + +The Configurable Math Library (CML) is distributed under the terms of the +Boost Software License, v1.0 (see cml/LICENSE for details). + + *-----------------------------------------------------------------------*/ +/** @file + * @brief + */ + +#ifndef quaternion_print_h +#define quaternion_print_h + +#include + +namespace cml { + +/* NOTE: Made 'plain' quaternion output the default (Jesse) */ + +/* #if !defined(CML_PLAIN_QUATERNION_OUTPUT) */ +#if defined(CML_COMPLEX_QUATERNION_OUTPUT) + +template std::ostream& +operator<<(std::ostream& os, const cml::quaternion& q) +{ + os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]); + os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "i"; + os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "j"; + os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]) << "k"; + return os; +} + +template std::ostream& +operator<<(std::ostream& os, const cml::quaternion& q) +{ + os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]) << "i"; + os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "j"; + os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "k"; + os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]); + return os; +} + +#else + +/** Output a quaternion to a std::ostream. */ +template std::ostream& +operator<<(std::ostream& os, const cml::quaternion& q) +{ + typedef typename cml::quaternion::order_type order_type; + enum { + W = order_type::W, + X = order_type::X, + Y = order_type::Y, + Z = order_type::Z + }; + + os << "[ " + << " " << q[W] + << " " << q[X] + << " " << q[Y] + << " " << q[Z] + << " ]"; + + return os; +} + +#endif + +/** Output a quaternion expression to a std::ostream. */ +template< class XprT > inline std::ostream& +operator<<(std::ostream& os, const et::QuaternionXpr& q) +{ + typedef typename et::QuaternionXpr::result_type quaternion_type; + + os << quaternion_type(q); + /* XXX This temporary can be removed by templating the stream insertion + * operators above. + */ + + return os; +} + +} // namespace cml + +#endif + +// ------------------------------------------------------------------------- +// vim:ft=cpp