X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Fpoly.h;h=186075ac54a95028998aceeaf728b4b29a8018b4;hp=b9675670e51f880e1fbe47627f480417bf6c1d96;hb=34ea6c36c2a3377546d0e8038f0d4f43b5e3cb6f;hpb=64cbdc0d10e611af20d4d375ff6319793da8e6f5 diff --git a/lib/gfxpoly/poly.h b/lib/gfxpoly/poly.h index b967567..186075a 100644 --- a/lib/gfxpoly/poly.h +++ b/lib/gfxpoly/poly.h @@ -3,12 +3,17 @@ #include #include "../q.h" +#include "../types.h" //#define DEBUG -#define CHECKS +//#define CHECKS -typedef enum {DIR_UP, DIR_DOWN} segment_dir_t; -typedef enum {EVENT_CROSS, EVENT_END, EVENT_CORNER, EVENT_START, EVENT_HORIZONTAL} eventtype_t; +/* features */ +#define SPLAY +#define DONT_REMEMBER_CROSSINGS + +typedef enum {DIR_UP, DIR_DOWN, DIR_UNKNOWN} segment_dir_t; +typedef enum {EVENT_CROSS, EVENT_END, EVENT_START, EVENT_HORIZONTAL} eventtype_t; typedef enum {SLOPE_POSITIVE, SLOPE_NEGATIVE} slope_t; typedef struct _point { @@ -20,51 +25,75 @@ typedef struct _fillstyle { char is_filled; } fillstyle_t; -typedef struct _edge { - point_t a; - point_t b; - fillstyle_t*style; - int tmp; - struct _edge *next; -} edge_t; - typedef struct _windstate { char is_filled; int wind_nr; - int num_polygons; } windstate_t; +/* TODO: maybe we should merge windcontext and windrule */ +typedef struct _windcontext +{ + int num_polygons; +} windcontext_t; + typedef struct _windrule { - windstate_t (*start)(int num_polygons); - windstate_t (*add)(windstate_t left, fillstyle_t*edge, segment_dir_t dir, int polygon_nr); + windstate_t (*start)(windcontext_t* num_polygons); + windstate_t (*add)(windcontext_t*context, windstate_t left, fillstyle_t*edge, segment_dir_t dir, int polygon_nr); fillstyle_t* (*diff)(windstate_t*left, windstate_t*right); } windrule_t; +#define SEGNR(s) ((s)?(s)->nr:-1) + +typedef struct _gfxpolystroke { + segment_dir_t dir; + int points_size; + int num_points; + point_t*points; + fillstyle_t*fs; + struct _gfxpolystroke*next; +} gfxpolystroke_t; +typedef struct _gfxpoly { + double gridsize; + gfxpolystroke_t*strokes; +} gfxpoly_t; + typedef struct _segment { point_t a; point_t b; point_t delta; 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) - int minx, maxx; + int32_t minx, maxx; segment_dir_t dir; fillstyle_t*fs; fillstyle_t*fs_out; +#ifdef CHECKS char fs_out_ok; +#endif int polygon_nr; windstate_t wind; - int nr; + ptroff_t nr; +#ifdef SPLAY + struct _segment*parent; + struct _segment*leftchild; + struct _segment*rightchild; +#endif struct _segment*left; struct _segment*right; char changed; point_t pos; + gfxpolystroke_t*stroke; + int stroke_pos; + +#ifndef DONT_REMEMBER_CROSSINGS dict_t scheduled_crossings; +#endif } segment_t; #define LINE_EQ(p,s) ((double)(s)->delta.y*(p).x - (double)(s)->delta.x*(p).y - (s)->k) @@ -83,26 +112,13 @@ typedef struct _segment { #define XDIFF(s1,s2,ypos) (((s1)->k + (double)(s1)->delta.x*ypos)*(s2)->delta.y - \ ((s2)->k + (double)(s2)->delta.x*ypos)*(s1)->delta.y) -typedef struct _gfxpoly { - double gridsize; - edge_t*edges; -} gfxpoly_t; - void gfxpoly_fail(char*expr, char*file, int line, const char*function); -gfxpoly_t* gfxpoly_new(double gridsize); char gfxpoly_check(gfxpoly_t*poly); int gfxpoly_size(gfxpoly_t*poly); void gfxpoly_dump(gfxpoly_t*poly); -gfxpoly_t* gfxpoly_save(gfxpoly_t*poly, const char*filename); -gfxpoly_t* gfxpoly_process(gfxpoly_t*poly, windrule_t*windrule); - -typedef struct _event { - eventtype_t type; - point_t p; - segment_t*s1; - segment_t*s2; -} event_t; +void gfxpoly_save(gfxpoly_t*poly, const char*filename); +gfxpoly_t* gfxpoly_process(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context); #ifndef CHECKS #ifdef assert