1 #ifndef GLUI_INTERNAL_H
2 #define GLUI_INTERNAL_H
3 
4 #include <cstdio>
5 #include <cmath>
6 
7 #ifndef AND
8 #define AND &&
9 #define OR  ||
10 #define NOT !
11 #endif
12 
13 #ifndef MAX
14 #define MAX(a,b)  ((a)>(b) ? (a) : (b))
15 #define MIN(a,b)  ((a)<(b) ? (a) : (b))
16 #endif
17 
18 #ifndef ABS
19 #define ABS(a) ((a)>=0 ? (a) : (-(a)))
20 #endif
21 
22 /********************  bit comparisons and operations ***************/
23 #ifndef TEST_BIT
24 #define TEST_BIT( x, b )   (((x) & (1<<(b))) != 0 )
25 #define SET_BIT( x, b )    ((x) |= (1 << (b)))
26 #define CLEAR_BIT( x, b )  ((x) &= ~(1 << (b)))
27 #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
28 #endif
29 
30 #ifndef TEST_AND
31 #define TEST_AND( a, b ) ((a&b)==b)
32 #endif
33 
34 
35 #ifndef M_PI
36 #define M_PI 3.141592654
37 #endif
38 
39 /*********** flush the stdout and stderr output streams *************/
40 #ifndef flushout
41 #define flushout fflush(stdout)
42 #define flusherr fflush(stderr)
43 #endif
44 
45 /********** Debugging functions *************************************/
46 #ifndef error_return
47 #define error_return( c ); {fprintf(stderr,c);return;}
48 #endif
49 
50 /************************* floating-point random ********************/
51 #ifndef randf
52 #define randf()  ((float) rand() / (float)RAND_MAX )
53 #endif
54 
55 #ifndef SIGN
56 #define SIGN(x) ((x)>=0 ?  1  :  -1)
57 #endif
58 
59 /****************** conversion between degrees and radians **********/
60 #ifndef DEG2RAD
61 #define DEG2RAD(x) ((x)/180.0*M_PI)
62 #define RAD2DEG(x) ((x)/M_PI*180.0)
63 #endif
64 
65 /***************** clamp a value to some fixed interval *************/
66 #ifndef CLAMP
67 #define CLAMP(x,lo,hi)  {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
68 #endif
69 
70 /************ check if a value lies within a closed interval *********/
71 #ifndef IN_BOUNDS
72 #define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
73 #endif
74 
75 /************ check if a 2D point lies within a 2D box ***************/
76 #ifndef PT_IN_BOX
77 #define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
78 ( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
79 #endif
80 
81 /****** check if value lies on proper side of another value     *****/
82 /*** if side is positive => proper side is positive, else negative **/
83 #ifndef CHECK_PROPER_SIDE
84 #define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
85 #endif
86 
87 
88 /***** Small value when we want to do a comparison to 'close to zero' *****/
89 #ifndef FUDGE
90 #define FUDGE .00001
91 #endif
92 
93 
94 /******************* swap two values, using a temp variable *********/
95 #ifndef SWAP2
96 #define SWAP2(a,b,t) {t=a;a=b;b=t;}
97 #endif
98 
99 #define VEC3_TO_ARRAY(v,a)  a[0]=v[0], a[1]=v[1], a[2]=v[2]
100 
101 /**** Return the ASCII control code given the non-control ASCII character */
102 #define CTRL(c) ( (c>=('a'-1)) ? (c-'a'+1) : (c-'A'+1) )
103 
104 
105 #endif /* GLUI_INTERNAL_H */
106