WFMath  0.3.12
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 <cfloat>
00030 
00031 #ifdef _MSC_VER
00032   #if _MSC_VER < 1500
00033     #error "You are using an older version of MSVC++ with extremely poor"
00034     #error "template support. Please use at least version 2008,"
00035     #error "or try a different compiler."
00036   #endif
00037 #endif
00038 
00040 namespace WFMath {
00041 
00042 // WFMath::Foo::toAtlas() has to return a definite type,
00043 // we deal with supporting both 0.4 and 0.6 by forward declaring
00044 // types which we define in the AtlasConv header
00045 class AtlasInType;
00046 class AtlasOutType;
00047 
00048 template<int dim> class AxisBox;
00049 template<int dim> class Ball;
00050 template<int dim> class Point;
00051 template<int dim> class Polygon;
00052 template<int dim> class RotBox;
00053 template<int dim> class RotMatrix;
00054 template<int dim> class Segment;
00055 template<int dim> class Vector;
00056 class Quaternion;
00057 
00058 // Constants
00059 
00061 const double Pi         = 3.14159265358979323846264338327950288419716939937508;
00063 const double SqrtPi     = 1.77245385090551602729816748334114518279754945612237;
00065 const double LogPi      = 1.14472988584940017414342735135305871164729481291530;
00067 const double Sqrt2      = 1.41421356237309504880168872420969807856967187537693;
00069 const double Sqrt3      = 1.73205080756887729352744634150587236694280525381037;
00071 const double Log2       = 0.69314718055994530941723212145817656807550013436025;
00072 
00074 #define WFMATH_PRECISION_FUDGE_FACTOR 30
00075 
00076 #define WFMATH_MAX_NORM_AGE ((WFMATH_PRECISION_FUDGE_FACTOR * 2) / 3)
00077 
00079 typedef float CoordType;
00081 #define WFMATH_EPSILON          (WFMATH_PRECISION_FUDGE_FACTOR * FLT_EPSILON)
00082 
00084 #define WFMATH_MAX              FLT_MAX
00085 
00086 #define WFMATH_MIN              FLT_MIN
00087 
00088 // Basic comparisons
00089 
00090 double _ScaleEpsilon(double x1, double x2, double epsilon);
00091 double _ScaleEpsilon(const CoordType* x1, const CoordType* x2,
00092                      int length, double epsilon = WFMATH_EPSILON);
00093 
00095 
00102 template<class C>
00103 inline bool Equal(const C& c1, const C& c2, double epsilon = WFMATH_EPSILON)
00104         {return c1.isEqualTo(c2, epsilon);}
00105 
00106 bool Equal(double x1, double x2, double epsilon = WFMATH_EPSILON);
00107 // Avoid template and expensive casts from float to doubles.
00108 bool Equal(float x1, float x2, double epsilon = WFMATH_EPSILON);
00109 
00110 // These let us avoid including <algorithm> for the sake of
00111 // std::max() and std::min().
00112 
00113 inline CoordType FloatMax(CoordType a, CoordType b)
00114         {return (a > b) ? a : b;}
00115 inline CoordType FloatMin(CoordType a, CoordType b)
00116         {return (a < b) ? a : b;}
00117 inline CoordType FloatClamp(CoordType val, CoordType min, CoordType max)
00118         {return (min >= val) ? min : (max <= val ? max : val);}
00119 
00120 inline double DoubleMax(double a, double b)
00121         {return (a > b) ? a : b;}
00122 inline double DoubleMin(double a, double b)
00123         {return (a < b) ? a : b;}
00124 inline double DoubleClamp(double val, double min, double max)
00125         {return (min >= val) ? min : (max <= val ? max : val);}
00126 
00127 } // namespace WFMath
00128 
00129 #endif // WFMATH_CONST_H