17 typedef unsigned char Uint8;
18 typedef signed short Int16;
19 typedef unsigned short Uint16;
20 typedef signed int Int32;
21 typedef unsigned int Uint32;
22 typedef signed long long Int64;
23 typedef unsigned long long Uint64;
26 const int MaxInt = (std::numeric_limits<int>::max)();
27 const double MaxDouble = (std::numeric_limits<double>::max)();
28 const double MinDouble = (std::numeric_limits<double>::min)();
29 const float MaxFloat = (std::numeric_limits<float>::max)();
30 const float MinFloat = (std::numeric_limits<float>::min)();
33 const float Pi = 3.14159f;
34 const float TwoPi = Pi * 2;
35 const float HalfPi = Pi / 2;
36 const float QuarterPi = Pi / 4;
45 inline bool isNaN(T val)
55 inline float DegreesToRadians(
float degrees)
57 return TwoPi * (degrees/360.f);
77 inline bool InRange(
float start,
float end,
float val)
81 if ( (val > start) && (val < end) )
return true;
87 if ( (val < start) && (val > end) )
return true;
100 T Maximum(
const T& v1,
const T& v2)
102 return v1 > v2 ? v1 : v2;
115 inline int RandInt(
int x,
int y) {
return rand()%(y-x+1)+x;}
121 inline float RandFloat(){
return ((rand())/(RAND_MAX+1.0));}
157 inline float RandGaussian(
float mean = 0.0,
float standard_deviation = 1.0)
161 static int use_last = 0;
174 w = x1 * x1 + x2 * x2;
178 w = sqrt( (-2.0 * log( w ) ) / w );
184 return( mean + y1 * standard_deviation );
198 inline float Sigmoid(
float input,
float response = 1.0)
200 return ( 1.0 / ( 1.0 + exp(-input / response)));
211 inline T MaxOf(
const T& a,
const T& b)
213 if (a>b)
return a;
return b;
224 inline T MinOf(
const T& a,
const T& b)
226 if (a<b)
return a;
return b;
237 template <
class T,
class U,
class V>
238 inline void Clamp(T& arg,
const U& minVal,
const V& maxVal)
240 assert ( (minVal < maxVal) &&
"<Clamp>MaxVal < MinVal!");
260 int integral = (int)val;
261 float mantissa = val - integral;
282 int integral = (int)val;
283 float mantissa = val - integral;
285 if (mantissa < offset)
304 if (fabs(a-b) < 1E-12)
320 if (fabs(a-b) < 1E-12)
335 inline float Average(
const std::vector<T>& v)
339 for (
unsigned int i=0; i < v.size(); ++i)
341 average += (float)v[i];
344 return average / (float)v.size();
355 float average = Average(v);
357 for (
unsigned int i=0; i<v.size(); ++i)
359 sd += (v[i] - average) * (v[i] - average);
373 template <
class container>
374 inline void DeleteSTLContainer(container& c)
376 for (
typename container::iterator it = c.begin(); it!=c.end(); ++it)
390 inline void DeleteSTLMap(map& m)
392 for (
typename map::iterator it = m.begin(); it!=m.end(); ++it)
401 #endif //UTILITIES_HPP