Rev 10 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#ifndef __CGLA_H
#define __CGLA_H
#ifndef OLD_C_HEADERS
#include <cmath>
#include <climits>
#include <cassert>
#else
#include <math.h>
#include <limits.h>
#include <assert.h>
#endif
#include <algorithm>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#endif
namespace CGLA {
/** Numerical constant representing something large.
value is a bit arbitrary */
const float BIG=10e+30f;
/** Numerical constant represents something extremely small.
value is a bit arbitrary */
const float MINUTE=10e-30f;
/** Numerical constant represents something very small.
value is a bit arbitrary */
const float TINY=3e-7f;
/** Numerical constant represents something small.
value is a bit arbitrary */
const float SMALL=10e-2f;
const float SQRT3=sqrt(3.0f);
/// Useful enum that represents coordiante axes.
enum Axis {XAXIS=0,YAXIS=1,ZAXIS=2};
template<class Scalar>
Scalar s_min(Scalar a, Scalar b)
{
return a<b ? a : b;
}
template<class Scalar>
Scalar s_max(Scalar a, Scalar b)
{
return a>b ? a : b;
}
///Template for a function that squares the argument.
template <class Scalar>
inline Scalar sqr(Scalar x) {///
return x*x;}
/// Scalaremplate for a function that returns the cube of the argument.
template <class Scalar>
inline Scalar qbe(Scalar x) {///
return x*x*x;}
template <class Scalar>
inline bool is_zero(Scalar x) {return (x > -MINUTE && x < MINUTE);}
template <class Scalar>
inline bool is_tiny(Scalar x) {return (x > -TINY && x < TINY);}
/** What power of 2 ?. if x is the argument, find the largest
y so that 2^y <= x */
inline int two_to_what_power(int x)
{
if (x<1)
return -1;
int i = 0;
while (x != 1) {x>>=1;i++;}
return i;
}
#ifdef __sgi
inline int round(float x) {return int(rint(x));}
#else
inline int round(float x) {return int(x+0.5);}
#endif
template<class T>
inline T sign(T x) {return x>=T(0) ? 1 : -1;}
template<class T>
inline T int_pow(T x, int k)
{
T y = static_cast<T>(1);
for(int i=0;i<k;++i)
y *= x;
return y;
}
}
#endif