Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

const.h

00001 // const.h (Defined constants for the WFMath library)
00002 //
00003 //  The WorldForge Project
00004 //  Copyright (C) 2001, 2002  The WorldForge Project
00005 //
00006 //  This program 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 //  This program 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 this program; if not, write to the Free Software
00018 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 //
00020 //  For information about WorldForge and its authors, please contact
00021 //  the Worldforge Web Site at http://www.worldforge.org.
00022 
00023 // Author: Ron Steinke
00024 // Created: 2001-12-7
00025 
00026 #ifndef WFMATH_CONST_H
00027 #define WFMATH_CONST_H
00028 
00029 #include <float.h>
00030 // The next two aren't used in this file, but are used
00031 // everywhere else in the library.
00032 #include <assert.h>
00033 #include <math.h>
00034 
00035 #ifdef _MSC_VER
00036   #if _MSC_VER < 1300
00037     #error "You are using an older version of MSVC++ with extremely poor"
00038     #error "template support. Please use at least version 7.0, where the"
00039     #error "template support is merely bad, or try a different compiler."
00040   #else
00041     // The name of this one is somewhat misleading. The problem is,
00042     // while you can _define_ specializations of template functions,
00043     // you can't _declare_ them.
00044     #define WFMATH_NO_CLASS_FUNCTION_SPECIALIZATION 1
00045     // This one means exactly what it says
00046     #define WFMATH_NO_TEMPLATES_AS_TEMPLATE_PARAMETERS 1
00047   #endif
00048 #endif
00049 
00050 // Forward declarations for all classes
00051 #include <iosfwd>
00052 namespace Atlas { namespace Message { class Object;}}
00053 
00055 namespace WFMath {
00056 
00057 // Constants
00058 
00060 const double Pi         = 3.14159265358979323846264338327950288419716939937508;
00062 const double SqrtPi     = 1.77245385090551602729816748334114518279754945612237;
00064 const double LogPi      = 1.14472988584940017414342735135305871164729481291530;
00066 const double Sqrt2      = 1.41421356237309504880168872420969807856967187537693;
00068 const double Sqrt3      = 1.73205080756887729352744634150587236694280525381037;
00070 const double Log2       = 0.69314718055994530941723212145817656807550013436025;
00071 
00073 typedef float CoordType;
00074 
00077 #define WFMATH_EPSILON          (30 * FLT_EPSILON)
00078 
00080 #define WFMATH_MAX              FLT_MAX
00081 
00082 #define WFMATH_MIN              FLT_MIN
00083 
00084 // Basic comparisons
00085 
00086 double _ScaleEpsilon(double x1, double x2, double epsilon);
00087 double _ScaleEpsilon(const CoordType* x1, const CoordType* x2,
00088                      int length, double epsilon = WFMATH_EPSILON);
00089 
00091 
00098 template<class C>
00099 inline bool Equal(const C& c1, const C& c2, double epsilon = WFMATH_EPSILON)
00100         {return c1.isEqualTo(c2, epsilon);}
00101 
00102 bool Equal(double x1, double x2, double epsilon = WFMATH_EPSILON);
00103 // Avoid template, make sure floats are cast to doubles.
00104 inline bool Equal(float x1, float x2, double epsilon = WFMATH_EPSILON)
00105         {return Equal((double) x1, (double) x2, epsilon);}
00106 
00107 // These let us avoid including <algorithm> for the sake of
00108 // std::max() and std::min().
00109 
00110 inline CoordType FloatMax(CoordType a, CoordType b)
00111         {return (a > b) ? a : b;}
00112 inline CoordType FloatMin(CoordType a, CoordType b)
00113         {return (a < b) ? a : b;}
00114 inline CoordType FloatClamp(CoordType val, CoordType min, CoordType max)
00115         {return (min >= val) ? min : (max <= val ? max : val);}
00116 
00117 } // namespace WFMath
00118 
00119 #endif // WFMATH_CONST_H

Generated on Wed May 28 09:20:31 2003 for WFMath by doxygen1.3-rc3