Debian Codegraph @

converter/other/pamtosvg/curve.h

raw symbols SCIP
1 /* curve.h: data structures for the conversion from pixels to splines. */
2
3 #ifndef CURVE_H
4 #define CURVE_H
5
6 #include "autotrace.h"
7 #include "point.h"
8
9 /* We are simultaneously manipulating two different representations of
10 the same outline: one based on (x,y) positions in the plane, and one
11 based on parametric splines. (We are trying to match the latter to
12 the former.) Although the original (x,y)'s are pixel positions,
13 i.e., integers, after filtering they are reals.
14 */
15
16 typedef struct {
17 /*----------------------------------------------------------------------------
18 A point in a curve (i.e. a component of a curve).
19 -----------------------------------------------------------------------------*/
20 Point coord;
21 /* Location in space of the point */
22 float distance;
23 /* Distance point is along the curve, as a fraction of the
24 curve length. This is invalid until after someone has called
25 curve_updateDistance() on the curve.
26 */
27 } CurvePoint;
28
29
30
31 typedef struct Curve {
32 /*----------------------------------------------------------------------------
33 An ordered list of contiguous points in the raster, with no corners
34 in it. I.e. something that could reasonably be fit to a spline.
35 -----------------------------------------------------------------------------*/
36 CurvePoint * pointList;
37 /* Array of the points in the curve. Malloc'ed. Size is 'length'.
38 if 'length' is zero, this is meaningless and no memory is
39 allocated.
40 */
41 unsigned int length;
42 /* Number of points in the curve */
43 bool cyclic;
44 /* The curve is cyclic, i.e. it didn't have any corners, after all, so
45 the last point is adjacent to the first.
46 */
47
48 /* 'previous' and 'next' links are for the doubly linked list which is
49 a chain of all curves in an outline. The chain is a cycle for a
50 closed outline and linear for an open outline.
51 */
52 struct Curve * previous;
53 struct Curve * next;
54 } Curve;
55
56 #define CURVE_POINT(c, n) ((c)->pointList[n].coord)
57 #define LAST_CURVE_POINT(c) ((c)->pointList[(c)->length-1].coord)
58 #define CURVE_DIST(c, n) ((c)->pointList[n].distance)
59 #define LAST_CURVE_DIST(c) ((c)->pointList[(c)->length-1].distance)
60 #define CURVE_LENGTH(c) ((c)->length)
61
62 #define CURVE_CYCLIC(c) ((c)->cyclic)
63
64 /* If the curve is cyclic, the next and previous points should wrap
65 around; otherwise, if we get to the end, we return CURVE_LENGTH and
66 -1, respectively. */
67 #define CURVE_NEXT(c, n) \
68 ((n) + 1 >= CURVE_LENGTH (c) \
69 ? CURVE_CYCLIC (c) ? ((n) + 1) % CURVE_LENGTH (c) : CURVE_LENGTH (c) \
70 : (n) + 1)
71 #define CURVE_PREV(c, n) \
72 ((signed int) (n) - 1 < 0 \
73 ? CURVE_CYCLIC (c) ? (signed int) CURVE_LENGTH (c) + (signed int) (n) - 1 : -1\
74 : (signed int) (n) - 1)
75
76 #define PREVIOUS_CURVE(c) ((c)->previous)
77 #define NEXT_CURVE(c) ((c)->next)
78
79
80 Curve *
81 curve_new(void);
82
83 Curve *
84 curve_copyMost(Curve * const curveP);
85
86 void
87 curve_move(Curve * const dstP,
88 Curve * const srcP);
89
90 void
91 curve_free(Curve * const curveP);
92
93 void
94 curve_appendPoint(Curve * const curveP,
95 Point const coord);
96
97 void
98 curve_appendPixel(Curve * const curveP,
99 pm_pixelcoord const p);
100
101 void
102 curve_setDistance(Curve * const curveP);
103
104 void
105 curve_log(Curve * const curveP,
106 bool const print_t);
107 void
108 curve_logEntire(Curve * const curveP);
109
110 typedef struct {
111 /*----------------------------------------------------------------------------
112 An ordered list of contiguous curves of a particular color.
113 -----------------------------------------------------------------------------*/
114 Curve ** data;
115 /* data[i] is the handle of the ith curve in the list */
116 unsigned length;
117 bool clockwise;
118 pixel color;
119 bool open;
120 /* The curve list does not form a closed shape; i.e. the last
121 curve doesn't end where the first one starts.
122 */
123 } CurveList;
124
125 /* Number of curves in the list. */
126 #define CURVE_LIST_LENGTH(c_l) ((c_l).length)
127 #define CURVE_LIST_EMPTY(c_l) ((c_l).length == 0)
128
129 /* Access the individual curves. */
130 #define CURVE_LIST_ELT(c_l, n) ((c_l).data[n])
131 #define LAST_CURVE_LIST_ELT(c_l) ((c_l).data[CURVE_LIST_LENGTH (c_l) - 1])
132
133 /* Says whether the outline that this curve list represents moves
134 clockwise or counterclockwise. */
135 #define CURVE_LIST_CLOCKWISE(c_l) ((c_l).clockwise)
136
137
138 CurveList
139 curve_newList(void);
140
141 void
142 curve_freeList(CurveList * const curveListP);
143
144 void
145 curve_appendList(CurveList * const curveListP,
146 Curve * const curveP);
147
148 /* And a character is a list of outlines. I named this
149 `curve_list_array_type' because `curve_list_list_type' seemed pretty
150 monstrous. */
151 typedef struct {
152 CurveList * data;
153 unsigned length;
154 } CurveListArray;
155
156 /* Turns out we can use the same definitions for lists of lists as for
157 just lists. But we define the usual names, just in case. */
158 #define CURVE_LIST_ARRAY_LENGTH CURVE_LIST_LENGTH
159 #define CURVE_LIST_ARRAY_ELT CURVE_LIST_ELT
160 #define LAST_CURVE_LIST_ARRAY_ELT LAST_CURVE_LIST_ELT
161
162 CurveListArray
163 curve_newListArray(void);
164
165 void
166 curve_freeListArray(const CurveListArray * const curveListArrayP,
167 at_progress_func notify_progress,
168 void * const client_data);
169
170 void
171 curve_appendArray(CurveListArray * const curveListArrayP,
172 CurveList const curveList);
173
174 #endif