WFMath  0.3.12
const.h
1 // const.h (Defined constants for the WFMath library)
2 //
3 // The WorldForge Project
4 // Copyright (C) 2001, 2002 The WorldForge Project
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 //
20 // For information about WorldForge and its authors, please contact
21 // the Worldforge Web Site at http://www.worldforge.org.
22 
23 // Author: Ron Steinke
24 // Created: 2001-12-7
25 
26 #ifndef WFMATH_CONST_H
27 #define WFMATH_CONST_H
28 
29 #include <cfloat>
30 
31 #ifdef _MSC_VER
32  #if _MSC_VER < 1500
33  #error "You are using an older version of MSVC++ with extremely poor"
34  #error "template support. Please use at least version 2008,"
35  #error "or try a different compiler."
36  #endif
37 #endif
38 
40 namespace WFMath {
41 
42 // WFMath::Foo::toAtlas() has to return a definite type,
43 // we deal with supporting both 0.4 and 0.6 by forward declaring
44 // types which we define in the AtlasConv header
45 class AtlasInType;
46 class AtlasOutType;
47 
48 template<int dim> class AxisBox;
49 template<int dim> class Ball;
50 template<int dim> class Point;
51 template<int dim> class Polygon;
52 template<int dim> class RotBox;
53 template<int dim> class RotMatrix;
54 template<int dim> class Segment;
55 template<int dim> class Vector;
56 class Quaternion;
57 
58 // Constants
59 
61 const double Pi = 3.14159265358979323846264338327950288419716939937508;
63 const double SqrtPi = 1.77245385090551602729816748334114518279754945612237;
65 const double LogPi = 1.14472988584940017414342735135305871164729481291530;
67 const double Sqrt2 = 1.41421356237309504880168872420969807856967187537693;
69 const double Sqrt3 = 1.73205080756887729352744634150587236694280525381037;
71 const double Log2 = 0.69314718055994530941723212145817656807550013436025;
72 
74 #define WFMATH_PRECISION_FUDGE_FACTOR 30
75 #define WFMATH_MAX_NORM_AGE ((WFMATH_PRECISION_FUDGE_FACTOR * 2) / 3)
77 
79 typedef float CoordType;
81 #define WFMATH_EPSILON (WFMATH_PRECISION_FUDGE_FACTOR * FLT_EPSILON)
82 
84 #define WFMATH_MAX FLT_MAX
85 #define WFMATH_MIN FLT_MIN
87 
88 // Basic comparisons
89 
90 double _ScaleEpsilon(double x1, double x2, double epsilon);
91 double _ScaleEpsilon(const CoordType* x1, const CoordType* x2,
92  int length, double epsilon = WFMATH_EPSILON);
93 
95 
102 template<class C>
103 inline bool Equal(const C& c1, const C& c2, double epsilon = WFMATH_EPSILON)
104  {return c1.isEqualTo(c2, epsilon);}
105 
106 bool Equal(double x1, double x2, double epsilon = WFMATH_EPSILON);
107 // Avoid template and expensive casts from float to doubles.
108 bool Equal(float x1, float x2, double epsilon = WFMATH_EPSILON);
109 
110 // These let us avoid including <algorithm> for the sake of
111 // std::max() and std::min().
112 
113 inline CoordType FloatMax(CoordType a, CoordType b)
114  {return (a > b) ? a : b;}
115 inline CoordType FloatMin(CoordType a, CoordType b)
116  {return (a < b) ? a : b;}
117 inline CoordType FloatClamp(CoordType val, CoordType min, CoordType max)
118  {return (min >= val) ? min : (max <= val ? max : val);}
119 
120 inline double DoubleMax(double a, double b)
121  {return (a > b) ? a : b;}
122 inline double DoubleMin(double a, double b)
123  {return (a < b) ? a : b;}
124 inline double DoubleClamp(double val, double min, double max)
125  {return (min >= val) ? min : (max <= val ? max : val);}
126 
127 } // namespace WFMath
128 
129 #endif // WFMATH_CONST_H
const double Log2
The natural logarithm of 2.
Definition: const.h:71
const double Pi
The constant pi.
Definition: const.h:61
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
Definition: const.h:53
const double SqrtPi
The square root of pi.
Definition: const.h:63
A dim dimensional box, lying at an arbitrary angle.
Definition: const.h:52
bool Equal(const C &c1, const C &c2, double epsilon=WFMATH_EPSILON)
Test for equality up to precision epsilon.
Definition: const.h:103
A polygon, all of whose points lie in a plane, embedded in dim dimensions.
Definition: const.h:51
A dim dimensional vector.
Definition: const.h:55
const double Sqrt3
The square root of 3.
Definition: const.h:69
float CoordType
Basic floating point type.
Definition: const.h:79
const double LogPi
The natural logarithm of pi.
Definition: const.h:65
A line segment embedded in dim dimensions.
Definition: const.h:54
A normalized quaterion.
Definition: quaternion.h:39
A dim dimensional point.
Definition: const.h:50
const double Sqrt2
The square root of 2.
Definition: const.h:67