13 #define DONT_REMEMBER_CROSSINGS
15 typedef enum {DIR_UP, DIR_DOWN, DIR_UNKNOWN} segment_dir_t;
16 typedef enum {EVENT_CROSS, EVENT_END, EVENT_START, EVENT_HORIZONTAL} eventtype_t;
17 typedef enum {SLOPE_POSITIVE, SLOPE_NEGATIVE} slope_t;
19 #define INVALID_COORD (0x7fffffff)
20 typedef struct _point {
26 typedef struct _fillstyle {
30 typedef struct _windstate
36 /* TODO: maybe we should merge windcontext and windrule */
37 typedef struct _windcontext
42 typedef struct _windrule
44 windstate_t (*start)(windcontext_t* num_polygons);
45 windstate_t (*add)(windcontext_t*context, windstate_t left, fillstyle_t*edge, segment_dir_t dir, int polygon_nr);
46 fillstyle_t* (*diff)(windstate_t*left, windstate_t*right);
49 #define SEGNR(s) ((s)?(s)->nr:-1)
51 typedef struct _gfxpolystroke {
57 struct _gfxpolystroke*next;
59 typedef struct _gfxpoly {
61 gfxpolystroke_t*strokes;
64 typedef struct _segment {
68 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)
83 struct _segment*parent;
84 struct _segment*leftchild;
85 struct _segment*rightchild;
88 struct _segment*right;
93 gfxpolystroke_t*stroke;
96 #ifndef DONT_REMEMBER_CROSSINGS
97 dict_t scheduled_crossings;
101 #define LINE_EQ(p,s) ((double)(s)->delta.y*(p).x - (double)(s)->delta.x*(p).y - (s)->k)
103 /* x1 + ((x2-x1)*(y-y1)) / dy =
104 (x1*(y2-y1) + (x2-x1)*(y-y1)) / dy =
105 (x1*(y2-y) + x2 *(y-y1)) / dy =
106 (x1*y2 - x2*y1 + x2*y - y*x1) / dy =
107 (k + x2*y - x1*y) / dy
110 //#define XPOS(s,ypos) ((s)->a.x + ((s)->delta.x * (double)((ypos) - (s)->a.y)) / (s)->delta.y)
111 #define XPOS(s,ypos) (((s)->k + (double)(s)->delta.x*ypos) / (s)->delta.y)
113 #define XPOS_INT(s,ypos) ((int)ceil(XPOS((s),ypos)))
114 #define XDIFF(s1,s2,ypos) (((s1)->k + (double)(s1)->delta.x*ypos)*(s2)->delta.y - \
115 ((s2)->k + (double)(s2)->delta.x*ypos)*(s1)->delta.y)
117 void gfxpoly_fail(char*expr, char*file, int line, const char*function);
119 char gfxpoly_check(gfxpoly_t*poly);
120 int gfxpoly_num_segments(gfxpoly_t*poly);
121 int gfxpoly_size(gfxpoly_t*poly);
122 void gfxpoly_dump(gfxpoly_t*poly);
123 void gfxpoly_save(gfxpoly_t*poly, const char*filename);
124 gfxpoly_t* gfxpoly_process(gfxpoly_t*poly1, gfxpoly_t*poly2, windrule_t*windrule, windcontext_t*context);
126 gfxpoly_t* gfxpoly_intersect(gfxpoly_t*p1, gfxpoly_t*p2);
127 gfxpoly_t* gfxpoly_union(gfxpoly_t*p1, gfxpoly_t*p2);
135 #define assert(x) ((x)?0:gfxpoly_fail(__STRING(x), __FILE__, __LINE__, __PRETTY_FUNCTION__))