Subversion Repositories gelsvn

Rev

Rev 12 | Rev 39 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 jab 1
#ifndef __CGLA_CGLA_H__
2
#define __CGLA_CGLA_H__
2 bj 3
 
4
#include <cmath>
5
#include <climits>
6
#include <cassert>
7
#include <algorithm>
8
 
9
#ifndef M_PI
10
#define M_PI 3.14159265358979323846
11
#define M_PI_2 1.57079632679489661923
12
#endif
13
 
12 jab 14
namespace CGLA 
15
{
21 jrf 16
  /** Procedural definition of NAN */  
17
  const float CGLA_NAN = log(-1.0f);
18
 
19
  /** NAN is used for initialization of vectors and matrices
20
      in debug mode */
21
  const float CGLA_INIT_VALUE = CGLA_NAN;
22
 
12 jab 23
  /** Numerical constant representing something large.
24
      value is a bit arbitrary */
25
  const double BIG=10e+30;
2 bj 26
 
12 jab 27
  /** Numerical constant represents something extremely small.
28
      value is a bit arbitrary */
29
  const double MINUTE=10e-30;
2 bj 30
 
12 jab 31
  /** Numerical constant represents something very small.
32
      value is a bit arbitrary */
33
  const double TINY=3e-7;
2 bj 34
 
12 jab 35
  /** Numerical constant represents something small.
36
      value is a bit arbitrary */
37
  const double SMALL=10e-2;
2 bj 38
 
12 jab 39
  const double SQRT3=sqrt(3.0);
2 bj 40
 
12 jab 41
  /// Useful enum that represents coordiante axes.
42
  enum Axis {XAXIS=0,YAXIS=1,ZAXIS=2};
2 bj 43
 
12 jab 44
  template<class Scalar>
45
  Scalar s_min(Scalar a, Scalar b)
46
  {
47
    return a<b ? a : b;
48
  }
2 bj 49
 
12 jab 50
  template<class Scalar>
51
  Scalar s_max(Scalar a, Scalar b)
52
  {
53
    return a>b ? a : b;
54
  }
2 bj 55
 
12 jab 56
  ///Template for a function that squares the argument.
57
  template <class Scalar>
58
  inline Scalar sqr(Scalar x) {///
59
    return x*x;}
2 bj 60
 
12 jab 61
  /// Scalaremplate for a function that returns the cube of the argument.
62
  template <class Scalar>
63
  inline Scalar qbe(Scalar x) {///
64
    return x*x*x;}
2 bj 65
 
12 jab 66
  template <class Scalar>
67
  inline bool is_zero(Scalar x)	{return (x > -MINUTE && x < MINUTE);}
2 bj 68
 
12 jab 69
  template <class Scalar>
70
  inline bool is_tiny(Scalar x)	{return (x > -TINY && x < TINY);}
2 bj 71
 
12 jab 72
  /** What power of 2 ?. if x is the argument, find the largest 
73
      y so that 2^y <= x */
74
  inline int two_to_what_power(int x) 
75
  {
76
    if (x<1) 
77
      return -1;
78
    int i = 0;
79
    while (x != 1) {x>>=1;i++;}
80
    return i;
81
  }
2 bj 82
 
83
#ifdef __sgi
12 jab 84
  inline int round(float x) {return int(rint(x));}
2 bj 85
#else
12 jab 86
  inline int round(float x) {return int(x+0.5);}
2 bj 87
#endif
88
 
12 jab 89
  template<class T>
90
  inline T sign(T x) {return x>=T(0) ? 1 : -1;}
2 bj 91
 
92
 
12 jab 93
  template<class T>
94
  inline T int_pow(T x, int k) 
95
  {
96
    T y = static_cast<T>(1);
97
    for(int i=0;i<k;++i)
98
      y *= x;
99
    return y;
100
  }
2 bj 101
 
12 jab 102
  template<class T, class S>
103
  void raw_assign(T& a,  const S* b)
104
  {
105
    memcpy(static_cast<void*>(a.get()),static_cast<const void*>(b),sizeof(T));
106
  }
2 bj 107
 
108
}
109
 
110
#endif