| 1 |
|
| 2 |
|
| 3 |
#ifndef CURVE_H |
| 4 |
#define CURVE_H |
| 5 |
|
| 6 |
#include "autotrace.h" |
| 7 |
#include "point.h" |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
typedef struct { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
Point coord; |
| 21 |
|
| 22 |
float distance; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
} CurvePoint; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
typedef struct Curve { |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
CurvePoint * pointList; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
unsigned int length; |
| 42 |
|
| 43 |
bool cyclic; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 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 |
|
| 65 |
|
| 66 |
|
| 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 |
|
| 113 |
|
| 114 |
Curve ** data; |
| 115 |
|
| 116 |
unsigned length; |
| 117 |
bool clockwise; |
| 118 |
pixel color; |
| 119 |
bool open; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
} CurveList; |
| 124 |
|
| 125 |
|
| 126 |
#define CURVE_LIST_LENGTH(c_l) ((c_l).length) |
| 127 |
#define CURVE_LIST_EMPTY(c_l) ((c_l).length == 0) |
| 128 |
|
| 129 |
|
| 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 |
|
| 134 |
|
| 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 |
|
| 149 |
|
| 150 |
|
| 151 |
typedef struct { |
| 152 |
CurveList * data; |
| 153 |
unsigned length; |
| 154 |
} CurveListArray; |
| 155 |
|
| 156 |
|
| 157 |
|
| 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 |