Subversion Repositories gelsvn

Rev

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