26 #ifndef WFMATH_CONST_H 27 #define WFMATH_CONST_H 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." 48 template<
int dim>
class AxisBox;
49 template<
int dim>
class Ball;
61 #define WFMATH_PRECISION_FUDGE_FACTOR 30 63 template<
typename FloatType>
64 struct numeric_constants
67 static FloatType pi();
69 static FloatType sqrt_pi();
71 static FloatType log_pi();
73 static FloatType sqrt2();
75 static FloatType sqrt3();
77 static FloatType log2();
79 static FloatType epsilon();
83 struct numeric_constants<float>
86 return 3.14159265358979323846264338327950288419716939937508F;
88 static float sqrt_pi() {
89 return 1.77245385090551602729816748334114518279754945612237F;
91 static float log_pi() {
92 return 1.14472988584940017414342735135305871164729481291530F;
94 static float sqrt2() {
95 return 1.41421356237309504880168872420969807856967187537693F;
97 static float sqrt3() {
98 return 1.73205080756887729352744634150587236694280525381037F;
100 static float log2() {
101 return 0.69314718055994530941723212145817656807550013436025F;
103 static float epsilon() {
104 return (WFMATH_PRECISION_FUDGE_FACTOR *
105 std::numeric_limits<float>::epsilon());
110 struct numeric_constants<double>
113 return 3.14159265358979323846264338327950288419716939937508;
115 static double sqrt_pi() {
116 return 1.77245385090551602729816748334114518279754945612237;
118 static double log_pi() {
119 return 1.14472988584940017414342735135305871164729481291530;
121 static double sqrt2() {
122 return 1.41421356237309504880168872420969807856967187537693;
124 static double sqrt3() {
125 return 1.73205080756887729352744634150587236694280525381037;
127 static double log2() {
128 return 0.69314718055994530941723212145817656807550013436025;
130 static double epsilon() {
131 return (WFMATH_PRECISION_FUDGE_FACTOR *
132 std::numeric_limits<double>::epsilon());
137 #define WFMATH_MAX_NORM_AGE ((WFMATH_PRECISION_FUDGE_FACTOR * 2) / 3) 144 double _ScaleEpsilon(
double x1,
double x2,
double epsilon);
145 float _ScaleEpsilon(
float x1,
float x2,
float epsilon);
147 int length,
CoordType epsilon = numeric_constants<CoordType>::epsilon());
158 inline bool Equal(
const C& c1,
const C& c2,
CoordType epsilon = numeric_constants<CoordType>::epsilon())
159 {
return c1.isEqualTo(c2, epsilon);}
161 bool Equal(
double x1,
double x2,
double epsilon = numeric_constants<double>::epsilon());
163 bool Equal(
float x1,
float x2,
float epsilon = numeric_constants<float>::epsilon());
169 {
return (a > b) ? a : b;}
171 {
return (a < b) ? a : b;}
173 {
return (min >= val) ? min : (max <= val ? max : val);}
175 inline double DoubleMax(
double a,
double b)
176 {
return (a > b) ? a : b;}
177 inline double DoubleMin(
double a,
double b)
178 {
return (a < b) ? a : b;}
179 inline double DoubleClamp(
double val,
double min,
double max)
180 {
return (min >= val) ? min : (max <= val ? max : val);}
184 #endif // WFMATH_CONST_H bool Equal(const C &c1, const C &c2, CoordType epsilon=numeric_constants< CoordType >::epsilon())
Test for equality up to precision epsilon.
Definition: const.h:158
Generic library namespace.
Definition: atlasconv.h:45
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
Definition: const.h:53
A dim dimensional box, lying at an arbitrary angle.
Definition: const.h:52
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
float CoordType
Basic floating point type.
Definition: const.h:140
A line segment embedded in dim dimensions.
Definition: const.h:54
A normalized quaterion.
Definition: quaternion.h:35
A dim dimensional point.
Definition: const.h:50