auxiliary.h
Go to the documentation of this file.
00001 /* Copyright (C) 2001-2007 Peter Selinger.
00002    This file is part of Potrace. It is free software and it is covered
00003    by the GNU General Public License. See the file COPYING for details. */
00004 
00005 /* This header file collects some general-purpose macros (and static
00006    inline functions) that are used in various places. */
00007 
00008 #ifndef AUXILIARY_H
00009 #define AUXILIARY_H
00010 
00011 #ifdef HAVE_CONFIG_H
00012 #include "config.h"
00013 #endif
00014 
00015 /* ---------------------------------------------------------------------- */
00016 /* point arithmetic */
00017 
00018 #include "potracelib.h"
00019 
00020 struct point_s {
00021   long x;
00022   long y;
00023 };
00024 typedef struct point_s point_t;
00025 
00026 typedef potrace_dpoint_t dpoint_t;
00027 
00028 /* convert point_t to dpoint_t */
00029 static inline dpoint_t dpoint(point_t p) {
00030   dpoint_t res;
00031   res.x = p.x;
00032   res.y = p.y;
00033   return res;
00034 }
00035 
00036 /* range over the straight line segment [a,b] when lambda ranges over [0,1] */
00037 static inline dpoint_t interval(double lambda, dpoint_t a, dpoint_t b) {
00038   dpoint_t res;
00039 
00040   res.x = a.x + lambda * (b.x - a.x);
00041   res.y = a.y + lambda * (b.y - a.y);
00042   return res;
00043 }
00044 
00045 /* ---------------------------------------------------------------------- */
00046 /* some useful macros. Note: the "mod" macro works correctly for
00047    negative a. Also note that the test for a>=n, while redundant,
00048    speeds up the mod function by 70% in the average case (significant
00049    since the program spends about 16% of its time here - or 40%
00050    without the test). The "floordiv" macro returns the largest integer
00051    <= a/n, and again this works correctly for negative a, as long as
00052    a,n are integers and n>0. */
00053 
00054 /* integer arithmetic */
00055 
00056 static inline int mod(int a, int n) {
00057   return a>=n ? a%n : a>=0 ? a : n-1-(-1-a)%n;
00058 }
00059 
00060 static inline int floordiv(int a, int n) {
00061   return a>=0 ? a/n : -1-(-1-a)/n;
00062 }
00063 
00064 /* Note: the following work for integers and other numeric types. */
00065 #undef sign
00066 #undef abs
00067 #undef min
00068 #undef max
00069 #undef sq
00070 #undef cu
00071 #define sign(x) ((x)>0 ? 1 : (x)<0 ? -1 : 0)
00072 #define abs(a) ((a)>0 ? (a) : -(a))
00073 #define min(a,b) ((a)<(b) ? (a) : (b))
00074 #define max(a,b) ((a)>(b) ? (a) : (b))
00075 #define sq(a) ((a)*(a))
00076 #define cu(a) ((a)*(a)*(a))
00077 
00078 #endif /* AUXILIARY_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


portrait_painter
Author(s): Niklas Meinzer, Ina Baumgarten
autogenerated on Wed Dec 26 2012 16:00:42