• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

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 < 1300
00033     #error "You are using an older version of MSVC++ with extremely poor"
00034     #error "template support. Please use at least version 7.0, where the"
00035     #error "template support is merely bad, or try a different compiler."
00036   #else
00037     // The name of this one is somewhat misleading. The problem is,
00038     // while you can _define_ specializations of template functions,
00039     // you can't _declare_ them.
00040     #define WFMATH_NO_CLASS_FUNCTION_SPECIALIZATION 1
00041     // This one means exactly what it says
00042     #define WFMATH_NO_TEMPLATES_AS_TEMPLATE_PARAMETERS 1
00043   #endif
00044 #endif
00045 
00047 namespace WFMath {
00048 
00049 // WFMath::Foo::toAtlas() has to return a definite type,
00050 // we deal with supporting both 0.4 and 0.6 by forward declaring
00051 // types which we define in the AtlasConv header
00052 class AtlasInType;
00053 class AtlasOutType;
00054 
00055 template<const int dim> class AxisBox;
00056 template<const int dim> class Ball;
00057 template<const int dim> class Point;
00058 template<const int dim> class Polygon;
00059 template<const int dim> class RotBox;
00060 template<const int dim> class RotMatrix;
00061 template<const int dim> class Segment;
00062 template<const int dim> class Vector;
00063 class Quaternion;
00064 
00065 // Constants
00066 
00068 const double Pi         = 3.14159265358979323846264338327950288419716939937508;
00070 const double SqrtPi     = 1.77245385090551602729816748334114518279754945612237;
00072 const double LogPi      = 1.14472988584940017414342735135305871164729481291530;
00074 const double Sqrt2      = 1.41421356237309504880168872420969807856967187537693;
00076 const double Sqrt3      = 1.73205080756887729352744634150587236694280525381037;
00078 const double Log2       = 0.69314718055994530941723212145817656807550013436025;
00079 
00081 #define WFMATH_PRECISION_FUDGE_FACTOR 30
00082 
00083 #define WFMATH_MAX_NORM_AGE ((WFMATH_PRECISION_FUDGE_FACTOR * 2) / 3)
00084 
00086 typedef float CoordType;
00088 #define WFMATH_EPSILON          (WFMATH_PRECISION_FUDGE_FACTOR * FLT_EPSILON)
00089 
00091 #define WFMATH_MAX              FLT_MAX
00092 
00093 #define WFMATH_MIN              FLT_MIN
00094 
00095 // Basic comparisons
00096 
00097 double _ScaleEpsilon(double x1, double x2, double epsilon);
00098 double _ScaleEpsilon(const CoordType* x1, const CoordType* x2,
00099                      int length, double epsilon = WFMATH_EPSILON);
00100 
00102 
00109 template<class C>
00110 inline bool Equal(const C& c1, const C& c2, double epsilon = WFMATH_EPSILON)
00111         {return c1.isEqualTo(c2, epsilon);}
00112 
00113 bool Equal(double x1, double x2, double epsilon = WFMATH_EPSILON);
00114 // Avoid template and expensive casts from float to doubles.
00115 bool Equal(float x1, float x2, double epsilon = WFMATH_EPSILON);
00116 
00117 // These let us avoid including <algorithm> for the sake of
00118 // std::max() and std::min().
00119 
00120 inline CoordType FloatMax(CoordType a, CoordType b)
00121         {return (a > b) ? a : b;}
00122 inline CoordType FloatMin(CoordType a, CoordType b)
00123         {return (a < b) ? a : b;}
00124 inline CoordType FloatClamp(CoordType val, CoordType min, CoordType max)
00125         {return (min >= val) ? min : (max <= val ? max : val);}
00126 
00127 } // namespace WFMath
00128 
00129 #endif // WFMATH_CONST_H

Generated for WFMath by  doxygen 1.7.2