Main Page | Namespace List | Class List | File List | Namespace Members | Class 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 <cfloat> 00030 // The next two aren't used in this file, but are used 00031 // everywhere else in the library. 00032 #include <cassert> 00033 #include <cmath> 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 00054 namespace WFMath { 00055 00056 // WFMath::Foo::toAtlas() has to return a definite type, 00057 // we deal with supporting both 0.4 and 0.6 by forward declaring 00058 // types which we define in the AtlasConv header 00059 class AtlasInType; 00060 class AtlasOutType; 00061 00062 // Constants 00063 00065 const double Pi = 3.14159265358979323846264338327950288419716939937508; 00067 const double SqrtPi = 1.77245385090551602729816748334114518279754945612237; 00069 const double LogPi = 1.14472988584940017414342735135305871164729481291530; 00071 const double Sqrt2 = 1.41421356237309504880168872420969807856967187537693; 00073 const double Sqrt3 = 1.73205080756887729352744634150587236694280525381037; 00075 const double Log2 = 0.69314718055994530941723212145817656807550013436025; 00076 00078 #define WFMATH_PRECISION_FUDGE_FACTOR 30 00079 00080 #define WFMATH_MAX_NORM_AGE ((WFMATH_PRECISION_FUDGE_FACTOR * 2) / 3) 00081 00083 typedef float CoordType; 00085 #define WFMATH_EPSILON (WFMATH_PRECISION_FUDGE_FACTOR * FLT_EPSILON) 00086 00088 #define WFMATH_MAX FLT_MAX 00089 00090 #define WFMATH_MIN FLT_MIN 00091 00092 // Basic comparisons 00093 00094 double _ScaleEpsilon(double x1, double x2, double epsilon); 00095 double _ScaleEpsilon(const CoordType* x1, const CoordType* x2, 00096 int length, double epsilon = WFMATH_EPSILON); 00097 00099 00106 template<class C> 00107 inline bool Equal(const C& c1, const C& c2, double epsilon = WFMATH_EPSILON) 00108 {return c1.isEqualTo(c2, epsilon);} 00109 00110 bool Equal(double x1, double x2, double epsilon = WFMATH_EPSILON); 00111 // Avoid template, make sure floats are cast to doubles. 00112 inline bool Equal(float x1, float x2, double epsilon = WFMATH_EPSILON) 00113 {return Equal((double) x1, (double) x2, epsilon);} 00114 00115 // These let us avoid including <algorithm> for the sake of 00116 // std::max() and std::min(). 00117 00118 inline CoordType FloatMax(CoordType a, CoordType b) 00119 {return (a > b) ? a : b;} 00120 inline CoordType FloatMin(CoordType a, CoordType b) 00121 {return (a < b) ? a : b;} 00122 inline CoordType FloatClamp(CoordType val, CoordType min, CoordType max) 00123 {return (min >= val) ? min : (max <= val ? max : val);} 00124 00125 } // namespace WFMath 00126 00127 #endif // WFMATH_CONST_H

Generated on Tue Jul 27 21:41:56 2004 for WFMath by doxygen 1.3.7