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=dd73d3c58fdfa2ad7fccf9181c056d71ef1b9660;hp=0000000000000000000000000000000000000000;hb=c2321281bf12a7efaedde930422c7ddbc92080d4;hpb=87bc17e55b0c1dc73ecc66df856d3f08fd7a7724 diff --git a/src/Moof/cml/quaternion/quaternion_print.h b/src/Moof/cml/quaternion/quaternion_print.h new file mode 100644 index 0000000..dd73d3c --- /dev/null +++ b/src/Moof/cml/quaternion/quaternion_print.h @@ -0,0 +1,80 @@ +/* -*- 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) +{ + os << "["; + for (size_t i = 0; i < 4; ++i) { + os << " " << q[i]; + } + os << " ]"; + 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