Main Page   Class Hierarchy   Compound List   File List   Compound Members  

baMath.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2001-2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_base_baMath_h
00020 #define freecloth_base_baMath_h
00021 
00022 #ifndef freecloth_base_package_h
00023 #include <freecloth/base/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_base_types_h
00027 #include <freecloth/base/types.h>
00028 #endif
00029 
00030 #ifndef freecloth_base_math_h
00031 #include <freecloth/base/math.h>
00032 #endif
00033 
00034 #ifndef M_PI
00035 #define M_PI 3.14159f
00036 #endif
00037 
00038 FREECLOTH_NAMESPACE_START
00039 
00040 ////////////////////////////////////////////////////////////////////////////////
00041 /*!
00042  * \class BaMath freecloth/base/baMath.h
00043  * \brief Container for a variety of useful mathematics functions.
00044  *
00045  * This class is intended to provide clean platform-independent access to
00046  * standard routines. It also groups a number of useful new routines, such
00047  * as floating-point comparisons using tolerances.
00048  */
00049 
00050 class BaMath
00051 {
00052 public:
00053     // ----- static data members -----
00054 
00055     static const Float TOLERANCE;
00056 
00057     // ----- static member functions -----
00058 
00059     static Float ceil( Float );
00060     static Float floor( Float );
00061     static Float round( Float );
00062 
00063     //@{
00064     //! Note that no truncation is performed. If the value is out of
00065     //! range, it will be wrapped around.
00066     static Int8 ceilInt8( Float );
00067     static Int8 floorInt8( Float );
00068     static Int8 roundInt8( Float );
00069     static UInt8 ceilUInt8( Float );
00070     static UInt8 floorUInt8( Float );
00071     static UInt8 roundUInt8( Float );
00072 
00073     static Int16 ceilInt16( Float );
00074     static Int16 floorInt16( Float );
00075     static Int16 roundInt16( Float );
00076     static UInt16 ceilUInt16( Float );
00077     static UInt16 floorUInt16( Float );
00078     static UInt16 roundUInt16( Float );
00079 
00080     static Int32 ceilInt32( Float );
00081     static Int32 floorInt32( Float );
00082     static Int32 roundInt32( Float );
00083     static UInt32 ceilUInt32( Float );
00084     static UInt32 floorUInt32( Float );
00085     static UInt32 roundUInt32( Float );
00086     //@}
00087 
00088     //! This will cap values to the range [-128,127]
00089     static Int8 roundTruncInt8( Float );
00090     //! This will cap values to the range [0,255]
00091     static UInt8 roundTruncUInt8( Float );
00092     //! This will cap values to the range [-32768,32767]
00093     static Int16 roundTruncInt16( Float );
00094     //! This will cap values to the range [0,65535]
00095     static UInt16 roundTruncUInt16( Float );
00096 
00097     static Float abs( Float );
00098 
00099     //! Returns true if input is an integer (or within tolerance)
00100     static bool isInteger( Float );
00101     //! Returns true if input is a power of two.
00102     static bool isPow2( UInt32 );
00103     //! Rounds input up to nearest power of two.
00104     static UInt32 roundUpPow2( UInt32 );
00105 
00106     static Float sqr( Float );
00107     static Float sqrt( Float );
00108 
00109     static Float cos( Float );
00110     static Float sin( Float );
00111     static Float tan( Float );
00112     static Float arccos( Float );
00113     static Float arcsin( Float );
00114     static Float arctan( Float );
00115     static Float arctan2( Float y, Float x );
00116     static Float sinc( Float );
00117 
00118     static Float exp( Float );
00119     static Float log( Float );
00120 
00121     //! Returns a 32-bit value containing random bits, according to a 
00122     //! a pseudo-random uniform distribution.
00123     static UInt32 randomUInt32();
00124     //! Returns a 32-bit value in the range [0,nbVals) using a pseudo-random
00125     //! uniform distribution.
00126     static UInt32 randomUInt32( UInt32 nbVals );
00127 
00128     //! Returns a value between 0 and 1, in a pseudo-random uniform
00129     //! distribution.
00130     static Float randomFloat();
00131 
00132     //@{
00133     //! Values a and b are considered equal if they differ by less than the
00134     //! tolerance.
00135     static bool isEqual( Float a, Float b, Float tol = TOLERANCE );
00136     static bool isGreater( Float a, Float b, Float tol = TOLERANCE );
00137     static bool isLess( Float a, Float b, Float tol = TOLERANCE );
00138     //@}
00139 };
00140 
00141 FREECLOTH_NAMESPACE_END
00142 
00143 #include <freecloth/base/baMath.inline.h>
00144 
00145 #endif

Generated on Fri May 2 16:51:11 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002