pcb 4.1.1
An interactive printed circuit board layout editor.
|
00001 00019 #ifndef AUXILIARY_H 00020 #define AUXILIARY_H 00021 00022 #ifdef HAVE_CONFIG_H 00023 #include "config.h" 00024 #endif 00025 00026 /* ---------------------------------------------------------------------- */ 00027 /* point arithmetic */ 00028 00029 #include "potracelib.h" 00030 00031 struct point_s 00032 { 00033 long x; 00034 long y; 00035 }; 00036 typedef struct point_s point_t; 00037 00038 typedef potrace_dpoint_t dpoint_t; 00039 00043 static inline dpoint_t 00044 dpoint (point_t p) 00045 { 00046 dpoint_t res; 00047 res.x = p.x; 00048 res.y = p.y; 00049 return res; 00050 } 00051 00056 static inline dpoint_t 00057 interval (double lambda, dpoint_t a, dpoint_t b) 00058 { 00059 dpoint_t res; 00060 00061 res.x = a.x + lambda * (b.x - a.x); 00062 res.y = a.y + lambda * (b.y - a.y); 00063 return res; 00064 } 00065 00066 /* ---------------------------------------------------------------------- */ 00067 /* some useful macros. */ 00068 00069 /* integer arithmetic */ 00070 00079 static inline int 00080 mod (int a, int n) 00081 { 00082 return a >= n ? a % n : a >= 0 ? a : n - 1 - (-1 - a) % n; 00083 } 00084 00090 static inline int 00091 floordiv (int a, int n) 00092 { 00093 return a >= 0 ? a / n : -1 - (-1 - a) / n; 00094 } 00095 00096 /* Note: the following work for integers and other numeric types. */ 00097 #undef sign 00098 #undef abs 00099 #undef min 00100 #undef max 00101 #undef sq 00102 #undef cu 00103 #define sign(x) ((x)>0 ? 1 : (x)<0 ? -1 : 0) 00104 #define abs(a) ((a)>0 ? (a) : -(a)) 00105 #define min(a,b) ((a)<(b) ? (a) : (b)) 00106 #define max(a,b) ((a)>(b) ? (a) : (b)) 00107 #define sq(a) ((a)*(a)) 00108 #define cu(a) ((a)*(a)*(a)) 00109 00110 #endif /* AUXILIARY_H */