misc.h

Go to the documentation of this file.
00001 /* -*- C++ -*- ------------------------------------------------------------
00002  
00003 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
00004 
00005 The Configurable Math Library (CML) is distributed under the terms of the
00006 Boost Software License, v1.0 (see cml/LICENSE for details).
00007 
00008  *-----------------------------------------------------------------------*/
00013 #ifndef misc_h
00014 #define misc_h
00015 
00016 #include <cml/mathlib/checking.h>
00017 
00018 /* A few miscellaneous functions and helper classes.
00019  *
00020  * @note: This is somewhat ad-hoc and will probably all be replaced in a future
00021  * version of the CML (I don't think I even bothered to document these functions
00022  * on the website).
00023  */
00024 
00025 namespace cml {
00026 
00028 // N-d functions
00030 
00032 template < size_t N >
00033 vector< double, fixed<N> > zero()
00034 {
00035     typedef vector< double, fixed<N> > vector_type;
00036 
00037     vector_type result;
00038     result.zero();
00039     return result;
00040 }
00041 
00043 template < size_t N >
00044 vector< double, fixed<N> > axis(size_t i)
00045 {
00046     /* Checking */
00047     detail::CheckValidArg(i < N);
00048 
00049     typedef vector< double, fixed<N> > vector_type;
00050     vector_type result;
00051     result.cardinal(i);
00052     return result;
00053 }
00054 
00056 template < size_t N, size_t M >
00057 matrix< double, fixed<N,M>, row_basis, row_major > zero()
00058 {
00059     typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
00060 
00061     matrix_type result;
00062     result.zero();
00063     return result;
00064 }
00065 
00067 template < size_t N >
00068 matrix< double, fixed<N,N>, row_basis, row_major > identity()
00069 {
00070     typedef matrix< double, fixed<N,N>, row_basis, row_major > matrix_type;
00071 
00072     matrix_type result;
00073     result.identity();
00074     return result;
00075 }
00076 
00078 template < size_t N, size_t M >
00079 matrix< double, fixed<N,M>, row_basis, row_major > identity_transform()
00080 {
00081     typedef matrix< double, fixed<N,M>, row_basis, row_major > matrix_type;
00082 
00083     matrix_type result;
00084     identity_transform(result);
00085     return result;
00086 }
00087 
00089 // Zero vector
00091 
00093 inline vector< double, fixed<2> > zero_2D() {
00094     return zero<2>();
00095 }
00096 
00098 inline vector< double, fixed<3> > zero_3D() {
00099     return zero<3>();
00100 }
00101 
00103 inline vector< double, fixed<4> > zero_4D() {
00104     return zero<4>();
00105 }
00106 
00108 // Cardinal axis
00110 
00112 inline vector< double, fixed<2> > axis_2D(size_t i) {
00113     return axis<2>(i);
00114 }
00115 
00117 inline vector< double, fixed<3> > axis_3D(size_t i) {
00118     return axis<3>(i);
00119 }
00120 
00122 inline vector< double, fixed<2> > x_axis_2D() {
00123     return axis_2D(0);
00124 }
00125 
00127 inline vector< double, fixed<2> > y_axis_2D() {
00128     return axis_2D(1);
00129 }
00130 
00132 inline vector< double, fixed<3> > x_axis_3D() {
00133     return axis_3D(0);
00134 }
00135 
00137 inline vector< double, fixed<3> > y_axis_3D() {
00138     return axis_3D(1);
00139 }
00140 
00142 inline vector< double, fixed<3> > z_axis_3D() {
00143     return axis_3D(2);
00144 }
00145 
00147 // Zero matrix
00149 
00151 inline matrix< double, fixed<2,2>, row_basis, row_major > zero_2x2() {
00152     return zero<2,2>();
00153 }
00154 
00156 inline matrix< double, fixed<3,3>, row_basis, row_major > zero_3x3() {
00157     return zero<3,3>();
00158 }
00159 
00161 inline matrix< double, fixed<4,4>, row_basis, row_major > zero_4x4() {
00162     return zero<4,4>();
00163 }
00164 
00166 // Identity matrix
00168 
00170 inline matrix< double, fixed<2,2>, row_basis, row_major > identity_2x2() {
00171     return identity<2>();
00172 }
00173 
00175 inline matrix< double, fixed<3,3>, row_basis, row_major > identity_3x3() {
00176     return identity<3>();
00177 }
00178 
00180 inline matrix< double, fixed<4,4>, row_basis, row_major > identity_4x4() {
00181     return identity<4>();
00182 }
00183 
00185 // Identity transform matrix
00187 
00189 inline matrix< double,fixed<3,2>,row_basis,row_major > identity_transform_3x2() {
00190     return identity_transform<3,2>();
00191 }
00192 
00194 inline matrix< double,fixed<2,3>,col_basis,col_major > identity_transform_2x3() {
00195     return identity_transform<2,3>();
00196 }
00197 
00199 inline matrix< double,fixed<4,3>,row_basis,row_major > identity_transform_4x3() {
00200     return identity_transform<4,3>();
00201 }
00202 
00204 inline matrix< double,fixed<3,4>,col_basis,col_major > identity_transform_3x4() {
00205     return identity_transform<3,4>();
00206 }
00207 
00208 } // namespace cml
00209 
00210 #endif

Generated on Sat Jul 18 19:35:22 2009 for CML 1.0 by  doxygen 1.5.9