Rev 10 | Rev 39 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#ifndef __CGLA_CGLA_H__
#define __CGLA_CGLA_H__
#include <cmath>
#include <climits>
#include <cassert>
#include <algorithm>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#endif
#define CGLA_INIT_VALUE NAN
namespace CGLA
{
/** Numerical constant representing something large.
value is a bit arbitrary */
const double BIG=10e+30;
/** Numerical constant represents something extremely small.
value is a bit arbitrary */
const double MINUTE=10e-30;
/** Numerical constant represents something very small.
value is a bit arbitrary */
const double TINY=3e-7;
/** Numerical constant represents something small.
value is a bit arbitrary */
const double SMALL=10e-2;
const double SQRT3=sqrt(3.0);
/// 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;
}
template<class T, class S>
void raw_assign(T& a, const S* b)
{
memcpy(static_cast<void*>(a.get()),static_cast<const void*>(b),sizeof(T));
}
}
#endif