Code

Use subdirectories with icon sizes.
[inkscape.git] / src / libnr / nr-macros.h
1 #ifndef __NR_MACROS_H__
2 #define __NR_MACROS_H__
4 /*
5  * Pixel buffer rendering library
6  *
7  * Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * This code is in public domain
11  */
13 #include <math.h>
15 #if HAVE_STDLIB_H
16 #include <stdlib.h>
17 #endif
18 #include <assert.h>
20 #ifndef TRUE
21 #define TRUE (!0)
22 #endif
23 #ifndef FALSE
24 #define FALSE 0
25 #endif
26 #ifndef MAX
27 #define MAX(a,b) (((a) < (b)) ? (b) : (a))
28 #endif
29 #ifndef MIN
30 #define MIN(a,b) (((a) > (b)) ? (b) : (a))
31 #endif
33 /** Returns v bounded to within [a, b].  If v is NaN then returns a. 
34  *
35  *  \pre \a a \<= \a b.
36  */
37 #define NR_CLAMP(v,a,b) \
38         (assert (a <= b),       \
39          ((v) >= (a))   \
40          ? (((v) > (b)) \
41             ? (b)       \
42             : (v))      \
43          : (a))
45 #undef CLAMP  /* get rid of glib's version, which doesn't handle NaN correctly */
46 #define CLAMP(v,a,b) NR_CLAMP(v,a,b)
48 #define NR_DF_TEST_CLOSE(a,b,e) (fabs ((a) - (b)) <= (e))
50 // Todo: move these into nr-matrix.h
51 #define NR_RECT_DFLS_TEST_EMPTY(a) (((a)->x0 >= (a)->x1) || ((a)->y0 >= (a)->y1))
52 #define NR_RECT_DFLS_TEST_EMPTY_REF(a) (((a).x0 >= (a).x1) || ((a).y0 >= (a).y1))
53 #define NR_RECT_DFLS_TEST_INTERSECT(a,b) (((a)->x0 < (b)->x1) && ((a)->x1 > (b)->x0) && ((a)->y0 < (b)->y1) && ((a)->y1 > (b)->y0))
54 #define NR_RECT_DFLS_TEST_INTERSECT_REF(a,b) (((a).x0 < (b).x1) && ((a).x1 > (b).x0) && ((a).y0 < (b).y1) && ((a).y1 > (b).y0))
55 #define NR_RECT_DF_POINT_DF_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
56 #define NR_RECT_LS_POINT_LS_TEST_INSIDE(r,p) (((p)->x >= (r)->x0) && ((p)->x < (r)->x1) && ((p)->y >= (r)->y0) && ((p)->y < (r)->y1))
57 #define NR_RECT_LS_TEST_INSIDE(r,x,y) ((x >= (r)->x0) && (x < (r)->x1) && (y >= (r)->y0) && (y < (r)->y1))
59 #define NR_MATRIX_D_FROM_DOUBLE(d) ((NR::Matrix *) &(d)[0])
61 #endif