12 typedef enum {DIR_UP, DIR_DOWN, DIR_UNKNOWN} segment_dir_t;
13 typedef enum {EVENT_CROSS, EVENT_END, EVENT_START, EVENT_HORIZONTAL} eventtype_t;
14 typedef enum {SLOPE_POSITIVE, SLOPE_NEGATIVE} slope_t;
16 typedef struct _point {
21 typedef struct _fillstyle {
25 typedef struct _edge {
35 typedef struct _windstate
41 /* TODO: maybe we should merge windcontext and windrule */
42 typedef struct _windcontext
47 typedef struct _windrule
49 windstate_t (*start)(windcontext_t* num_polygons);
50 windstate_t (*add)(windcontext_t*context, windstate_t left, fillstyle_t*edge, segment_dir_t dir, int polygon_nr);
51 fillstyle_t* (*diff)(windstate_t*left, windstate_t*right);
54 #define SEGNR(s) ((s)?(s)->nr:-1)
56 typedef struct _gfxpolystroke {
62 typedef struct _gfxcompactpoly {
65 gfxpolystroke_t*strokes;
68 typedef struct _segment {
72 double k; //k = a.x*b.y-a.y*b.x = delta.y*a.x - delta.x*a.y (=0 for points on the segment)
87 struct _segment*parent;
88 struct _segment*leftchild;
89 struct _segment*rightchild;
92 struct _segment*right;
97 gfxpolystroke_t*stroke;
100 dict_t scheduled_crossings;
103 #define LINE_EQ(p,s) ((double)(s)->delta.y*(p).x - (double)(s)->delta.x*(p).y - (s)->k)
105 /* x1 + ((x2-x1)*(y-y1)) / dy =
106 (x1*(y2-y1) + (x2-x1)*(y-y1)) / dy =
107 (x1*(y2-y) + x2 *(y-y1)) / dy =
108 (x1*y2 - x2*y1 + x2*y - y*x1) / dy =
109 (k + x2*y - x1*y) / dy
112 //#define XPOS(s,ypos) ((s)->a.x + ((s)->delta.x * (double)((ypos) - (s)->a.y)) / (s)->delta.y)
113 #define XPOS(s,ypos) (((s)->k + (double)(s)->delta.x*ypos) / (s)->delta.y)
115 #define XPOS_INT(s,ypos) ((int)ceil(XPOS((s),ypos)))
116 #define XDIFF(s1,s2,ypos) (((s1)->k + (double)(s1)->delta.x*ypos)*(s2)->delta.y - \
117 ((s2)->k + (double)(s2)->delta.x*ypos)*(s1)->delta.y)
119 typedef struct _gfxpoly {
124 void gfxpoly_fail(char*expr, char*file, int line, const char*function);
126 gfxpoly_t* gfxpoly_new(double gridsize);
127 char gfxcompactpoly_check(gfxcompactpoly_t*poly);
128 int gfxcompactpoly_size(gfxcompactpoly_t*poly);
129 void gfxcompactpoly_dump(gfxcompactpoly_t*poly);
130 void gfxcompactpoly_save(gfxcompactpoly_t*poly, const char*filename);
131 gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context);
139 #define assert(x) ((x)?0:gfxpoly_fail(__STRING(x), __FILE__, __LINE__, __PRETTY_FUNCTION__))