gcode/auxiliary.h: Converted plain comments into doxygen comments.
[geda-pcb/pcjc2.git] / src / hid / gcode / auxiliary.h
blobb5e13233c4d39d45f5d6a97f54e9ab901623f83b
1 /*!
2 * \file src/hid/gcode/auxiliary.h
4 * \brief This header file collects some general-purpose macros (and
5 * static inline functions) that are used in various places.
7 * <hr>
9 * <h1><b>Copyright.</b></h1>\n
11 * PCB, interactive printed circuit board design
13 * Copyright (C) 2001-2007 Peter Selinger.
15 * This file is part of Potrace. It is free software and it is covered
16 * by the GNU General Public License. See the file COPYING for details.
19 #ifndef AUXILIARY_H
20 #define AUXILIARY_H
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
26 /* ---------------------------------------------------------------------- */
27 /* point arithmetic */
29 #include "potracelib.h"
31 struct point_s
33 long x;
34 long y;
36 typedef struct point_s point_t;
38 typedef potrace_dpoint_t dpoint_t;
40 /*!
41 * \brief Convert point_t to dpoint_t.
43 static inline dpoint_t
44 dpoint (point_t p)
46 dpoint_t res;
47 res.x = p.x;
48 res.y = p.y;
49 return res;
52 /*!
53 * \brief Range over the straight line segment [a,b] when lambda ranges
54 * over [0,1].
56 static inline dpoint_t
57 interval (double lambda, dpoint_t a, dpoint_t b)
59 dpoint_t res;
61 res.x = a.x + lambda * (b.x - a.x);
62 res.y = a.y + lambda * (b.y - a.y);
63 return res;
66 /* ---------------------------------------------------------------------- */
67 /* some useful macros. */
69 /* integer arithmetic */
71 /*!
72 * \brief .
74 * The "mod" macro works correctly for negative a.
75 * Also note that the test for a>=n, while redundant, speeds up the mod
76 * function by 70% in the average case (significant since the program
77 * spends about 16% of its time here - or 40% without the test).
79 static inline int
80 mod (int a, int n)
82 return a >= n ? a % n : a >= 0 ? a : n - 1 - (-1 - a) % n;
85 /*!
86 * \brief The "floordiv" macro returns the largest integer
87 * <= a/n, and again this works correctly for negative a, as long as
88 * a,n are integers and n>0.
90 static inline int
91 floordiv (int a, int n)
93 return a >= 0 ? a / n : -1 - (-1 - a) / n;
96 /* Note: the following work for integers and other numeric types. */
97 #undef sign
98 #undef abs
99 #undef min
100 #undef max
101 #undef sq
102 #undef cu
103 #define sign(x) ((x)>0 ? 1 : (x)<0 ? -1 : 0)
104 #define abs(a) ((a)>0 ? (a) : -(a))
105 #define min(a,b) ((a)<(b) ? (a) : (b))
106 #define max(a,b) ((a)>(b) ? (a) : (b))
107 #define sq(a) ((a)*(a))
108 #define cu(a) ((a)*(a)*(a))
110 #endif /* AUXILIARY_H */