Subversion Repositories gelsvn

Rev

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

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