1
#ifndef GLUI_INTERNAL_H
2
#define GLUI_INTERNAL_H
14
#define MAX(a,b) ((a)>(b) ? (a) : (b))
15
#define MIN(a,b) ((a)<(b) ? (a) : (b))
19
#define ABS(a) ((a)>=0 ? (a) : (-(a)))
22
/******************** bit comparisons and operations ***************/
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)))
31
#define TEST_AND( a, b ) ((a&b)==b)
36
#define M_PI 3.141592654
39
/*********** flush the stdout and stderr output streams *************/
41
#define flushout fflush(stdout)
42
#define flusherr fflush(stderr)
45
/********** Debugging functions *************************************/
47
#define error_return( c ); {fprintf(stderr,c);return;}
50
/************************* floating-point random ********************/
52
#define randf() ((float) rand() / (float)RAND_MAX )
56
#define SIGN(x) ((x)>=0 ? 1 : -1)
59
/****************** conversion between degrees and radians **********/
61
#define DEG2RAD(x) ((x)/180.0*M_PI)
62
#define RAD2DEG(x) ((x)/M_PI*180.0)
65
/***************** clamp a value to some fixed interval *************/
67
#define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
70
/************ check if a value lies within a closed interval *********/
72
#define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
75
/************ check if a 2D point lies within a 2D 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) )
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))
88
/***** Small value when we want to do a comparison to 'close to zero' *****/
94
/******************* swap two values, using a temp variable *********/
96
#define SWAP2(a,b,t) {t=a;a=b;b=t;}
99
#define VEC3_TO_ARRAY(v,a) a[0]=v[0], a[1]=v[1], a[2]=v[2]
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) )
105
#endif /* GLUI_INTERNAL_H */