]> Dogcows Code - chaz/yoink/blob - src/moof/cml/quaternion/quaternion_print.h
bugfix: win32 packaging script temp directories
[chaz/yoink] / src / moof / cml / quaternion / quaternion_print.h
1 /* -*- C++ -*- ------------------------------------------------------------
2
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
4
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
7
8 *-----------------------------------------------------------------------*/
9 /** @file
10 * @brief
11 */
12
13 #ifndef quaternion_print_h
14 #define quaternion_print_h
15
16 #include <iostream>
17
18 namespace cml {
19
20 /* NOTE: Made 'plain' quaternion output the default (Jesse) */
21
22 /* #if !defined(CML_PLAIN_QUATERNION_OUTPUT) */
23 #if defined(CML_COMPLEX_QUATERNION_OUTPUT)
24
25 template<typename E, class AT, class CT> std::ostream&
26 operator<<(std::ostream& os, const cml::quaternion<E,AT,scalar_first,CT>& q)
27 {
28 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]);
29 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "i";
30 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "j";
31 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]) << "k";
32 return os;
33 }
34
35 template<typename E, class AT, class CT> std::ostream&
36 operator<<(std::ostream& os, const cml::quaternion<E,AT,vector_first,CT>& q)
37 {
38 os << ((q[0] < 0)?" - ":"") << std::fabs(q[0]) << "i";
39 os << ((q[1] < 0)?" - ":" + ") << std::fabs(q[1]) << "j";
40 os << ((q[2] < 0)?" - ":" + ") << std::fabs(q[2]) << "k";
41 os << ((q[3] < 0)?" - ":" + ") << std::fabs(q[3]);
42 return os;
43 }
44
45 #else
46
47 /** Output a quaternion to a std::ostream. */
48 template<typename E, class AT, class OT, typename CT> std::ostream&
49 operator<<(std::ostream& os, const cml::quaternion<E,AT,OT,CT>& q)
50 {
51 typedef typename cml::quaternion<E,AT,OT,CT>::order_type order_type;
52 enum {
53 W = order_type::W,
54 X = order_type::X,
55 Y = order_type::Y,
56 Z = order_type::Z
57 };
58
59 os << "[ "
60 << " " << q[W]
61 << " " << q[X]
62 << " " << q[Y]
63 << " " << q[Z]
64 << " ]";
65
66 return os;
67 }
68
69 #endif
70
71 /** Output a quaternion expression to a std::ostream. */
72 template< class XprT > inline std::ostream&
73 operator<<(std::ostream& os, const et::QuaternionXpr<XprT>& q)
74 {
75 typedef typename et::QuaternionXpr<XprT>::result_type quaternion_type;
76
77 os << quaternion_type(q);
78 /* XXX This temporary can be removed by templating the stream insertion
79 * operators above.
80 */
81
82 return os;
83 }
84
85 } // namespace cml
86
87 #endif
88
89 // -------------------------------------------------------------------------
90 // vim:ft=cpp
This page took 0.034777 seconds and 4 git commands to generate.