Subversion Repositories gelsvn

Rev

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