Code

change API: separate functions creating a blur filter, one for a given item, another...
[inkscape.git] / src / trace / potrace / auxiliary.h
1 /* Copyright (C) 2001-2005 Peter Selinger.
2    This file is part of potrace. It is free software and it is covered
3    by the GNU General Public License. See the file COPYING for details. */
5 /* This header file collects some general-purpose macros (and static
6    inline functions) that are used in various places. */
8 #ifndef AUXILIARY_H
9 #define AUXILIARY_H
11 /* ---------------------------------------------------------------------- */
12 /* point arithmetic */
14 #include "potracelib.h"
16 struct point_s {
17   long x;
18   long y;
19 };
20 typedef struct point_s point_t;
22 typedef potrace_dpoint_t dpoint_t;
24 /* convert point_t to dpoint_t */
25 static inline dpoint_t dpoint(point_t p) {
26   dpoint_t res;
27   res.x = p.x;
28   res.y = p.y;
29   return res;
30 }
32 /* range over the straight line segment [a,b] when lambda ranges over [0,1] */
33 static inline dpoint_t interval(double lambda, dpoint_t a, dpoint_t b) {
34   dpoint_t res;
36   res.x = a.x + lambda * (b.x - a.x);
37   res.y = a.y + lambda * (b.y - a.y);
38   return res;
39 }
41 /* ---------------------------------------------------------------------- */
42 /* integer arithmetic */
44 static inline int mod(int a, int n) {
45   return a>=n ? a%n : a>=0 ? a : n-1-(-1-a)%n;
46 }
48 static inline int floordiv(int a, int n) {
49   return a>=0 ? a/n : -1-(-1-a)/n;
50 }
52 /* Note: the following work for integers and other numeric types. */
53 #define sign(x) ((x)>0 ? 1 : (x)<0 ? -1 : 0)
54 #define abs(a) ((a)>0 ? (a) : -(a))
55 #define min(a,b) ((a)<(b) ? (a) : (b))
56 #define max(a,b) ((a)>(b) ? (a) : (b))
57 #define sq(a) ((a)*(a))
58 #define cu(a) ((a)*(a)*(a))
60 #endif /* AUXILIARY_H */