Code

moving trunk for module inkscape
[inkscape.git] / src / trace / potrace / curve.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 #ifndef CURVE_H
6 #define CURVE_H
8 #include "auxiliary.h"
10 /* vertex is c[1] for tag=POTRACE_CORNER, and the intersection of
11    .c[-1][2]..c[0] and c[1]..c[2] for tag=POTRACE_CURVETO. alpha is only
12    defined for tag=POTRACE_CURVETO and is the alpha parameter of the curve:
13    .c[-1][2]..c[0] = alpha*(.c[-1][2]..vertex), and
14    c[2]..c[1] = alpha*(c[2]..vertex).
15    Beta is so that (.beta[i])[.vertex[i],.vertex[i+1]] = .c[i][2].
16 */
18 struct privcurve_s {
19   int n;            /* number of segments */
20   int *tag;         /* tag[n]: POTRACE_CORNER or POTRACE_CURVETO */
21   dpoint_t (*c)[3]; /* c[n][i]: control points. 
22                        c[n][0] is unused for tag[n]=POTRACE_CORNER */
23   dpoint_t *vertex; /* for POTRACE_CORNER, this equals c[1] */
24   double *alpha;    /* only for POTRACE_CURVETO */
25   double *alpha0;   /* "uncropped" alpha parameter - for debug output only */
26   double *beta;
27 };
28 typedef struct privcurve_s privcurve_t;
30 struct sums_s {
31   double x;
32   double y;
33   double x2;
34   double xy;
35   double y2;
36 };
37 typedef struct sums_s sums_t;
39 /* the path structure is filled in with information about a given path
40    as it is accumulated and passed through the different stages of the
41    potrace algorithm. Backends only need to read the fcurve and fm
42    fields of this data structure, but debugging backends may read
43    other fields. */
44 struct potrace_privpath_s {
45   int len;
46   point_t *pt;     /* pt[len]: path as extracted from bitmap */
47   int *lon;        /* lon[len]: (i,lon[i]) = longest straight line from i */
49   int x0, y0;      /* origin for sums */
50   sums_t *sums;    /* sums[len+1]: cache for fast summing */
52   int m;           /* length of optimal polygon */
53   int *po;         /* po[m]: optimal polygon */
55   privcurve_t curve;   /* curve[m]: array of curve elements */
56   privcurve_t ocurve;  /* ocurve[om]: array of curve elements */
57   privcurve_t *fcurve;  /* final curve: this points to either curve or
58                        ocurve. Do not free this separately. */
59 };
60 typedef struct potrace_privpath_s potrace_privpath_t;
62 /* shorter names */
63 typedef potrace_privpath_t privpath_t;
64 typedef potrace_path_t path_t;
66 path_t *path_new(void);
67 void path_free(path_t *p);
68 void pathlist_free(path_t *plist);
69 int privcurve_init(privcurve_t *curve, int n);
70 void privcurve_free_members(privcurve_t *curve);
71 void privcurve_to_curve(privcurve_t *pc, potrace_curve_t *c);
73 #endif /* CURVE_H */