H3DMath.h

00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00024 //
00026 
00027 #ifndef __H3DMATH_H__
00028 #define __H3DMATH_H__
00029 
00030 #include "Exception.h"
00031 #include <math.h>
00032 
00033 namespace H3D {
00034 
00036   namespace Constants {
00038     static const double pi = 3.1415926535897932384626433832795;
00039   }
00040 
00042   inline bool isPowerOfTwo( unsigned int i ) {
00043     return (((i - 1) & i) == 0);
00044   }
00045 
00048   inline unsigned int nextPowerOfTwo( unsigned int i ) {
00049     i--;
00050     i |= i >> 16;
00051     i |= i >> 8;
00052     i |= i >> 4;
00053     i |= i >> 2;
00054     i |= i >> 1;
00055     i++;
00056     return i;
00057   }
00058 
00060   template< class F >
00061   inline F H3DAbs( F f ) {
00062     return fabs( f );
00063   }
00064 
00066   template< class F >
00067   inline F H3DSqrt( F f ) {
00068     return sqrt( f );
00069   }
00070 
00072   template< class F >
00073   inline F H3DExp( F f ) {
00074     return exp( f );
00075   }
00076 
00078   template< class F >
00079   inline F H3DLog( F f ) {
00080     return log( f );
00081   }
00082 
00084   template< class F >
00085   inline F H3DLog10( F f ) {
00086     return log10( f );
00087   }
00088 
00090   template< class F, class T >
00091   inline F H3DPow( F f, T t ) {
00092     return pow( f, t );
00093   }
00094 
00096   inline double H3DPow( int f, int t ) {
00097     return pow( (double)f, (double)t );
00098   }
00099   
00101   template< class A >
00102   inline A H3DMax( const A &a, const A &b  ) {
00103     return max( a, b );
00104   }
00105     
00107   template< class A >
00108   inline A H3DMin( const A &a, const A &b  ) {
00109     return min( a, b );
00110   }
00111 
00113   template< class F >
00114   inline F H3DCos( F d ) {
00115     return cos( d );
00116   }
00117 
00119   template< class F >
00120   inline F H3DCosh( F d ) {
00121     return cosh( d );
00122   }
00123 
00125   template< class F >
00126   inline F H3DAcos( F d ) {
00127     return acos( d );
00128   }
00129 
00131   template< class F >
00132   inline  F H3DSin( F d ) {
00133     return sin( d );
00134   }
00135 
00137   template< class F >
00138   inline F H3DSinh( F d ) {
00139     return sinh( d );
00140   }
00141 
00143   template< class F >
00144   inline F H3DAsin( F d ) {
00145     return asin( d );
00146   }
00147 
00149   template< class F >
00150   inline F H3DTan( F d ) {
00151     return tan( d );
00152   }
00153 
00155   template< class F >
00156   inline F H3DTanh( F d ) {
00157     return tanh( d );
00158   }
00159 
00162   template< class F >
00163   inline F H3DAtan( F d ) {
00164     return atan( d );
00165   }
00166 
00171   template< class F >
00172   inline F H3DAtan2( F y, F x ) {
00173     return atan2( y, x );
00174   }
00175 
00177   template< class F >
00178   inline F H3DFloor( F f ) {
00179     return floor( f );
00180   }
00181 
00183   template< class F >
00184   inline F H3DCeil( F f ) {
00185     return ceil( f );
00186   }
00187 }
00188 
00189 #endif

Generated on Thu Aug 24 12:38:32 2006 for H3D API by  doxygen 1.4.5