1 #ifndef GLUI_INTERNAL_H
2 #define GLUI_INTERNAL_H
16 #define MAX(a,b) ((a)>(b) ? (a) : (b))
17 #define MIN(a,b) ((a)<(b) ? (a) : (b))
21 #define ABS(a) ((a)>=0 ? (a) : (-(a)))
24 /******************** bit comparisons and operations ***************/
26 #define TEST_BIT( x, b ) (((x) & (1<<(b))) != 0 )
27 #define SET_BIT( x, b ) ((x) |= (1 << (b)))
28 #define CLEAR_BIT( x, b ) ((x) &= ~(1 << (b)))
29 #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
33 #define TEST_AND( a, b ) ((a&b)==b)
38 #define M_PI 3.141592654
41 /*********** flush the stdout and stderr output streams *************/
43 #define flushout fflush(stdout)
44 #define flusherr fflush(stderr)
47 /********** Debugging functions *************************************/
49 #define error_return( c ); {fprintf(stderr,c);return;}
52 /************************* floating-point random ********************/
54 #define randf() ((float) rand() / (float)RAND_MAX )
58 #define SIGN(x) ((x)>=0 ? 1 : -1)
61 /****************** conversion between degrees and radians **********/
63 #define DEG2RAD(x) ((x)/180.0*M_PI)
64 #define RAD2DEG(x) ((x)/M_PI*180.0)
67 /***************** clamp a value to some fixed interval *************/
69 #define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
72 /************ check if a value lies within a closed interval *********/
74 #define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
77 /************ check if a 2D point lies within a 2D box ***************/
79 #define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
80 ( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
83 /****** check if value lies on proper side of another value *****/
84 /*** if side is positive => proper side is positive, else negative **/
85 #ifndef CHECK_PROPER_SIDE
86 #define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
90 /***** Small value when we want to do a comparison to 'close to zero' *****/
96 /******************* swap two values, using a temp variable *********/
98 #define SWAP2(a,b,t) {t=a;a=b;b=t;}
101 #define VEC3_TO_ARRAY(v,a) a[0]=v[0], a[1]=v[1], a[2]=v[2]
103 /**** Return the ASCII control code given the non-control ASCII character */
104 #define CTRL(c) ( (c>=('a'-1)) ? (c-'a'+1) : (c-'A'+1) )
107 #endif /* GLUI_INTERNAL_H */