GEL  2
GEL is a library for Geometry and Linear Algebra
/Users/jab/Documents/Teaching/02585/GEL2_and_demos/GEL/src/CGLA/ArithSqMat2x2Float.h
00001 #ifndef __CGLA_ARITHSQMAT2X2FLOAT_H__
00002 #define __CGLA_ARITHSQMAT2X2FLOAT_H__
00003 
00004 #include "ExceptionStandard.h"
00005 #include "ArithSqMatFloat.h"
00006 
00007 
00008 namespace CGLA 
00009 {
00010 
00011   CGLA_DERIVEEXCEPTION(Mat2x2fException);
00012 
00017   template<class V, class M>
00018   class ArithSqMat2x2Float: public ArithSqMatFloat<V,M, 2>
00019   {
00020   public:
00021 
00023     typedef V VectorType;
00024 
00026     typedef typename V::ScalarType ScalarType;
00027 
00028   public:
00029 
00031     ArithSqMat2x2Float(V a, V b): 
00032       ArithSqMatFloat<V, M, 2> (a,b) {}
00033 
00035     ArithSqMat2x2Float(ScalarType a, ScalarType b, 
00036                        ScalarType c, ScalarType d): 
00037       ArithSqMatFloat<V, M, 2>(V(a,b),V(c,d)) {}
00038   
00040     ArithSqMat2x2Float() {}
00041 
00043     explicit ArithSqMat2x2Float(ScalarType a): 
00044       ArithSqMatFloat<V, M, 2>(a) {}
00045   };
00046 
00049   template<class V, class M>
00050   inline typename ArithSqMat2x2Float<V,M>::ScalarType 
00051   determinant(const ArithSqMat2x2Float<V,M> & m)
00052   {
00053     return m[0][0]*m[1][1]-m[0][1]*m[1][0];
00054   }
00055 
00056   template<class V, class M>
00057   const M invert(const ArithSqMat2x2Float<V,M>& m)
00058   {
00059     typename M::ScalarType det = determinant(m);
00060     if( !is_tiny(fabs(det)))
00061       {
00062         return M(m[1][1]/det, -m[0][1]/det,-m[1][0]/det, m[0][0]/det);
00063       }
00064     throw Mat2x2fException("Cannot invert matrix");
00065   }
00066 
00067 
00068 }
00069 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations