]> Dogcows Code - chaz/yoink/blob - src/cml/quaternion/quaternion_functions.h
fixes for newer versions of g++
[chaz/yoink] / src / cml / quaternion / quaternion_functions.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 Functions on quaternions.
11 *
12 * @todo The functions that return quaternions and vectors should be changed
13 * to return quaternion expression nodes, as should the corresponding
14 * class methods.
15 */
16
17 #ifndef quaternion_functions_h
18 #define quaternion_functions_h
19
20 #include <cml/mathlib/checking.h> // For CheckQuat()
21 #include <cml/mathlib/epsilon.h>
22 #include <cml/util.h> // For acos_safe()
23
24 namespace cml {
25
26 /** Returns the real part of the quaternion. */
27 template<typename E, class AT, class OT, class CT>
28 inline typename quaternion<E,AT,OT,CT>::value_type
29 real(const quaternion<E,AT,OT,CT>& q)
30 {
31 return q.real();
32 }
33
34 /** Returns the real (scalar) part of the QuaternionXpr. */
35 template<typename XprT>
36 inline typename et::QuaternionXpr<XprT>::value_type
37 real(const et::QuaternionXpr<XprT>& e)
38 {
39 return e.real();
40 }
41
42 /** Returns the imaginary (vector) part of the quaternion. */
43 template<typename E, class AT, class OT, class CT>
44 inline typename quaternion<E,AT,OT,CT>::imaginary_type
45 imaginary(const quaternion<E,AT,OT,CT>& q)
46 {
47 return q.imaginary();
48 }
49
50 /** Returns the imaginary (vector) part of the QuaternionXpr. */
51 template<typename XprT>
52 //inline typename et::QuaternionXpr<XprT>::temporary_type
53 inline typename et::QuaternionXpr<XprT>::imaginary_type
54 imaginary(const et::QuaternionXpr<XprT>& e)
55 {
56 return e.imaginary();
57 }
58
59 /** Cayley norm of a quaternion. */
60 template<typename E, class AT, class OT, class CT>
61 inline typename quaternion<E,AT,OT,CT>::value_type
62 norm(const quaternion<E,AT,OT,CT>& arg)
63 {
64 return arg.length_squared();
65 }
66
67 /** Cayley norm of a QuaternionXpr. */
68 template<typename XprT>
69 inline typename XprT::value_type
70 norm(QUATXPR_ARG_TYPE arg)
71 {
72 return arg.length_squared();
73 }
74
75 /** Squared length of a quaternion. */
76 template<typename E, class AT, class OT, class CT>
77 inline typename quaternion<E,AT,OT,CT>::value_type
78 length_squared(const quaternion<E,AT,OT,CT>& arg)
79 {
80 return arg.length_squared();
81 }
82
83 /** Squared length of a quaternion expr. */
84 template<typename XprT>
85 inline typename XprT::value_type
86 length_squared(QUATXPR_ARG_TYPE arg)
87 {
88 return arg.length_squared();
89 }
90
91 /** Length of a quaternion. */
92 template<typename E, class AT, class OT, class CT>
93 inline typename quaternion<E,AT,OT,CT>::value_type
94 length(const quaternion<E,AT,OT,CT>& arg)
95 {
96 return arg.length();
97 }
98
99 /** Length of a quaternion expr. */
100 template<typename XprT>
101 inline typename XprT::value_type
102 length(QUATXPR_ARG_TYPE arg)
103 {
104 return arg.length();
105 }
106
107 /** Normalize a quaternion.
108 *
109 * The input quaternion is not changed.
110 */
111 template<typename E, class AT, class OT, class CT>
112 inline quaternion<E,AT,OT,CT>
113 normalize(const quaternion<E,AT,OT,CT>& arg)
114 {
115 typename quaternion<E,AT,OT,CT>::temporary_type result(arg);
116 result.normalize();
117 return result;
118 }
119
120 /** Normalize a quaternion expr. */
121 template<typename XprT>
122 inline typename XprT::temporary_type
123 normalize(QUATXPR_ARG_TYPE arg)
124 {
125 return arg.normalize();
126 }
127
128 /** Set a quaternion to the multiplicative identity.
129 *
130 * The input quaternion is not changed.
131 */
132 template<typename E, class AT, class OT, class CT>
133 inline quaternion<E,AT,OT,CT>
134 identity(const quaternion<E,AT,OT,CT>& arg)
135 {
136 typename quaternion<E,AT,OT,CT>::temporary_type result(arg);
137 result.identity();
138 return result;
139 }
140
141 /** Log of a quaternion or quaternion expression.
142 */
143 template < class QuatT >
144 typename QuatT::temporary_type log(
145 const QuatT& q,
146 typename QuatT::value_type tolerance =
147 epsilon<typename QuatT::value_type>::placeholder())
148 {
149 detail::CheckQuat(q);
150
151 return q.log();
152 }
153
154 /** Exponential function of a quaternion or quaternion expression.
155 */
156 template < class QuatT >
157 typename QuatT::temporary_type exp(
158 const QuatT& q,
159 typename QuatT::value_type tolerance =
160 epsilon<typename QuatT::value_type>::placeholder())
161 {
162 detail::CheckQuat(q);
163
164 return q.exp();
165 }
166
167 } // namespace cml
168
169 #endif
170
171 // -------------------------------------------------------------------------
172 // vim:ft=cpp
This page took 0.039496 seconds and 4 git commands to generate.