]> Dogcows Code - chaz/yoink/blob - src/cml/mathlib/misc.h
testing new non-autotools build system
[chaz/yoink] / src / cml / mathlib / misc.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 misc_h
14 #define misc_h
15
16 #include <cml/mathlib/checking.h>
17
18 /* A few miscellaneous functions and helper classes.
19 *
20 * @note: This is somewhat ad-hoc and will probably all be replaced in a future
21 * version of the CML (I don't think I even bothered to document these functions
22 * on the website).
23 */
24
25 namespace cml {
26
27 //////////////////////////////////////////////////////////////////////////////
28 // N-d functions
29 //////////////////////////////////////////////////////////////////////////////
30
31 /** Return an N-d zero vector */
32 template < size_t N >
33 vector< double, fixed<N> > zero()
34 {
35 typedef vector< double, fixed<N> > vector_type;
36
37 vector_type result;
38 result.zero();
39 return result;
40 }
41
42 /** Return an N-d cardinal axis by index */
43 template < size_t N >
44 vector< double, fixed<N> > axis(size_t i)
45 {
46 /* Checking */
47 detail::CheckValidArg(i < N);
48
49 typedef vector< double, fixed<N> > vector_type;
50 vector_type result;
51 result.cardinal(i);
52 return result;
53 }
54
55 /** Return an NxM zero matrix */
56 template < size_t N, size_t M >
57 matrix< double, fixed<N,M>, row_basis, row_major > zero()
58 {
59 typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
60
61 matrix_type result;
62 result.zero();
63 return result;
64 }
65
66 /** Return an NxN identity matrix */
67 template < size_t N >
68 matrix< double, fixed<N,N>, row_basis, row_major > identity()
69 {
70 typedef matrix< double, fixed<N,N>, row_basis, row_major > matrix_type;
71
72 matrix_type result;
73 result.identity();
74 return result;
75 }
76
77 /** Return an NxM identity transform */
78 template < size_t N, size_t M >
79 matrix< double, fixed<N,M>, row_basis, row_major > identity_transform()
80 {
81 typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
82
83 matrix_type result;
84 identity_transform(result);
85 return result;
86 }
87
88 //////////////////////////////////////////////////////////////////////////////
89 // Zero vector
90 //////////////////////////////////////////////////////////////////////////////
91
92 /** Return the 2D zero vector */
93 inline vector< double, fixed<2> > zero_2D() {
94 return zero<2>();
95 }
96
97 /** Return the 3D zero vector */
98 inline vector< double, fixed<3> > zero_3D() {
99 return zero<3>();
100 }
101
102 /** Return the 4D zero vector */
103 inline vector< double, fixed<4> > zero_4D() {
104 return zero<4>();
105 }
106
107 //////////////////////////////////////////////////////////////////////////////
108 // Cardinal axis
109 //////////////////////////////////////////////////////////////////////////////
110
111 /** Return a 2D cardinal axis by index */
112 inline vector< double, fixed<2> > axis_2D(size_t i) {
113 return axis<2>(i);
114 }
115
116 /** Return a 3D cardinal axis by index */
117 inline vector< double, fixed<3> > axis_3D(size_t i) {
118 return axis<3>(i);
119 }
120
121 /** Return a the 2D x cardinal axis */
122 inline vector< double, fixed<2> > x_axis_2D() {
123 return axis_2D(0);
124 }
125
126 /** Return a the 2D y cardinal axis */
127 inline vector< double, fixed<2> > y_axis_2D() {
128 return axis_2D(1);
129 }
130
131 /** Return a the 3D x cardinal axis */
132 inline vector< double, fixed<3> > x_axis_3D() {
133 return axis_3D(0);
134 }
135
136 /** Return a the 3D y cardinal axis */
137 inline vector< double, fixed<3> > y_axis_3D() {
138 return axis_3D(1);
139 }
140
141 /** Return a the 3D z cardinal axis */
142 inline vector< double, fixed<3> > z_axis_3D() {
143 return axis_3D(2);
144 }
145
146 //////////////////////////////////////////////////////////////////////////////
147 // Zero matrix
148 //////////////////////////////////////////////////////////////////////////////
149
150 /** Return the 2x2 zero matrix */
151 inline matrix< double, fixed<2,2>, row_basis, row_major > zero_2x2() {
152 return zero<2,2>();
153 }
154
155 /** Return the 3x3 zero matrix */
156 inline matrix< double, fixed<3,3>, row_basis, row_major > zero_3x3() {
157 return zero<3,3>();
158 }
159
160 /** Return the 4x4 zero matrix */
161 inline matrix< double, fixed<4,4>, row_basis, row_major > zero_4x4() {
162 return zero<4,4>();
163 }
164
165 //////////////////////////////////////////////////////////////////////////////
166 // Identity matrix
167 //////////////////////////////////////////////////////////////////////////////
168
169 /** Return the 2x2 identity matrix */
170 inline matrix< double, fixed<2,2>, row_basis, row_major > identity_2x2() {
171 return identity<2>();
172 }
173
174 /** Return the 3x3 identity matrix */
175 inline matrix< double, fixed<3,3>, row_basis, row_major > identity_3x3() {
176 return identity<3>();
177 }
178
179 /** Return the 4x4 identity matrix */
180 inline matrix< double, fixed<4,4>, row_basis, row_major > identity_4x4() {
181 return identity<4>();
182 }
183
184 //////////////////////////////////////////////////////////////////////////////
185 // Identity transform matrix
186 //////////////////////////////////////////////////////////////////////////////
187
188 /** Return a 3x2 identity transform */
189 inline matrix< double,fixed<3,2>,row_basis,row_major > identity_transform_3x2() {
190 return identity_transform<3,2>();
191 }
192
193 /** Return a 2x3 identity transform */
194 inline matrix< double,fixed<2,3>,col_basis,col_major > identity_transform_2x3() {
195 return identity_transform<2,3>();
196 }
197
198 /** Return a 4x3 identity transform */
199 inline matrix< double,fixed<4,3>,row_basis,row_major > identity_transform_4x3() {
200 return identity_transform<4,3>();
201 }
202
203 /** Return a 3x4 identity transform */
204 inline matrix< double,fixed<3,4>,col_basis,col_major > identity_transform_3x4() {
205 return identity_transform<3,4>();
206 }
207
208 } // namespace cml
209
210 #endif
This page took 0.038371 seconds and 4 git commands to generate.