00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef GV_MACROS_H
00018 #define GV_MACROS_H
00019
00020 #define NOT(v) (!(v))
00021 #ifndef FALSE
00022 #define FALSE 0
00023 #endif
00024 #ifndef TRUE
00025 #define TRUE NOT(FALSE)
00026 #endif
00027
00028 #ifndef NOTUSED
00029 #define NOTUSED(var) (void) var
00030 #endif
00031
00032 #ifdef DMALLOC
00033 #define NEW(t) (t*)calloc(1,sizeof(t))
00034 #define N_NEW(n,t) (t*)calloc((n),sizeof(t))
00035 #define GNEW(t) (t*)malloc(sizeof(t))
00036 #define N_GNEW(n,t) (t*)malloc((n)*sizeof(t))
00037 #define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type)))
00038 #define RALLOC(size,ptr,type) ((type*)realloc(ptr,(size)*sizeof(type)))
00039 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)recalloc(ptr,(size)*sizeof(type)):(type*)calloc((size),sizeof(type)))
00040 #else
00041 #define NEW(t) (t*)zmalloc(sizeof(t))
00042 #define N_NEW(n,t) (t*)zmalloc((n)*sizeof(t))
00043 #define GNEW(t) (t*)gmalloc(sizeof(t))
00044 #define N_GNEW(n,t) (t*)gmalloc((n)*sizeof(t))
00045 #define ALLOC(size,ptr,type) (ptr? (type*)grealloc(ptr,(size)*sizeof(type)):(type*)gmalloc((size)*sizeof(type)))
00046 #define RALLOC(size,ptr,type) ((type*)grealloc(ptr,(size)*sizeof(type)))
00047 #define ZALLOC(size,ptr,type,osize) (ptr? (type*)zrealloc(ptr,size,sizeof(type),osize):(type*)zmalloc((size)*sizeof(type)))
00048 #endif
00049
00050 #ifdef MIN
00051 #undef MIN
00052 #endif
00053 #define MIN(a,b) ((a)<(b)?(a):(b))
00054
00055 #ifdef MAX
00056 #undef MAX
00057 #endif
00058 #define MAX(a,b) ((a)>(b)?(a):(b))
00059
00060 #ifdef ABS
00061 #undef ABS
00062 #endif
00063 #define ABS(a) ((a) >= 0 ? (a) : -(a))
00064
00065 #ifndef MAXINT
00066 #define MAXINT ((int)(~(unsigned)0 >> 1))
00067 #endif
00068 #ifndef MAXSHORT
00069 #define MAXSHORT (0x7fff)
00070 #endif
00071 #ifndef MAXDOUBLE
00072 #define MAXDOUBLE 1.7976931348623157e+308
00073 #endif
00074 #ifndef MAXFLOAT
00075 #define MAXFLOAT ((float)3.40282347e+38)
00076 #endif
00077
00078 #ifdef BETWEEN
00079 #undef BETWEEN
00080 #endif
00081 #define BETWEEN(a,b,c) (((a) <= (b)) && ((b) <= (c)))
00082 #define INSIDE(p,b) (BETWEEN(b.LL.x,p.x,b.UR.x) && BETWEEN(b.LL.y,p.y,b.UR.y))
00083
00084 #define ROUND(f) ((f>=0)?(int)(f + .5):(int)(f - .5))
00085 #define RADIANS(deg) ((deg)/180.0 * PI)
00086 #define DEGREES(rad) ((rad)/PI * 180.0)
00087 #define DIST(x1,y1,x2,y2) (sqrt(((x1) - (x2))*((x1) - (x2)) + ((y1) - (y2))*((y1) - (y2))))
00088 #define POINTS_PER_INCH 72.0
00089 #define POINTS(f_inch) (ROUND((f_inch)*POINTS_PER_INCH))
00090 #define PS2INCH(ps) ((ps)/POINTS_PER_INCH)
00091
00092 #define isPinned(n) (ND_pinned(n) == P_PIN)
00093 #define hasPos(n) (ND_pinned(n) > 0)
00094 #define isFixed(n) (ND_pinned(n) > P_SET)
00095
00096 #define SET_CLUST_NODE(n) (ND_clustnode(n) = TRUE)
00097 #define IS_CLUST_NODE(n) (ND_clustnode(n))
00098 #define HAS_CLUST_EDGE(g) (GD_flags(g) & 1)
00099 #define SET_CLUST_EDGE(g) (GD_flags(g) |= 1)
00100
00101 #ifndef streq
00102 #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b))
00103 #endif
00104
00105 #define P2PF(p, pf) (pf.x = p.x, pf.y = p.y)
00106 #define PF2P(pf, p) (p.x = ROUND (pf.x), p.y = ROUND (pf.y))
00107
00108 #define XPAD(d) ((d).x += 4*GAP)
00109 #define YPAD(d) ((d).y += 2*GAP)
00110 #define PAD(d) {XPAD(d); YPAD(d);}
00111
00112 #define OTHERDIR(dir) ((dir == CCW) ? CW : CCW)
00113
00114 #define NEXTSIDE(side, dir) ((dir == CCW) ? \
00115 ((side & 0x8) ? BOTTOM : (side << 1)) : \
00116 ((side & 0x1) ? LEFT : (side >> 1)))
00117
00118 #endif