completed transition to smaller polygon struct
authorMatthias Kramm <kramm@matthias-kramms-macbook-pro.local>
Wed, 27 May 2009 02:34:43 +0000 (19:34 -0700)
committerMatthias Kramm <kramm@matthias-kramms-macbook-pro.local>
Wed, 27 May 2009 02:34:43 +0000 (19:34 -0700)
lib/gfxpoly/convert.c
lib/gfxpoly/convert.h
lib/gfxpoly/poly.c
lib/gfxpoly/poly.h
lib/gfxpoly/renderpoly.c
lib/gfxpoly/test.c

index 213cdad..7cf2329 100644 (file)
@@ -9,16 +9,6 @@
 /* factor that determines into how many line fragments a spline is converted */
 #define SUBFRACTION (2.4)
 
 /* factor that determines into how many line fragments a spline is converted */
 #define SUBFRACTION (2.4)
 
-static edge_t*edge_new(int x1, int y1, int x2, int y2)
-{
-    edge_t*s = rfx_calloc(sizeof(edge_t));
-    s->a.x = x1;
-    s->a.y = y1;
-    s->b.x = x2;
-    s->b.y = y2;
-    return s;
-}
-
 static inline int32_t convert_coord(double x, double z)
 {
     /* we clamp to 31 bit instead of 32 bit because we use
 static inline int32_t convert_coord(double x, double z)
 {
     /* we clamp to 31 bit instead of 32 bit because we use
@@ -125,56 +115,8 @@ static void convert_file(const char*filename, polywriter_t*w, double gridsize)
     }
 }
 
     }
 }
 
-typedef struct _stdpoly {
-    gfxpoly_t*poly;
-    double lastx,lasty;
-} stdpoly_t;
-
-static void stdmoveto(polywriter_t*w, int x, int y)
-{
-    stdpoly_t*d = (stdpoly_t*)w->internal;
-    d->lastx = x;d->lasty = y;
-}
-static void stdlineto(polywriter_t*w, int x, int y)
-{
-    stdpoly_t*d = (stdpoly_t*)w->internal;
-    int x1 = d->lastx;
-    int y1 = d->lasty;
-    int x2 = x;
-    int y2 = y;
-    if(x1!=x2 || y1!=y2) {
-        edge_t*s = edge_new(x1, y1, x2, y2);
-        s->next = d->poly->edges;
-        d->poly->edges = s;
-    }
-    d->lastx = x;d->lasty = y;
-}
-static void stdsetgridsize(polywriter_t*w, double gridsize)
-{
-    stdpoly_t*d = (stdpoly_t*)w->internal;
-    d->poly->gridsize = gridsize;
-}
-static void* stdfinish(polywriter_t*w)
-{
-    stdpoly_t*d = (stdpoly_t*)w->internal;
-    gfxpoly_t*poly =  d->poly;
-    free(w->internal);w->internal = 0;
-    return poly;
-}
-void gfxpolywriter_init(polywriter_t*w)
-{
-    w->moveto = stdmoveto;
-    w->lineto = stdlineto;
-    w->setgridsize = stdsetgridsize;
-    w->finish = stdfinish;
-    stdpoly_t*data = w->internal = malloc(sizeof(stdpoly_t));
-    data->poly = gfxpoly_new(1.0);
-    data->lastx = 0;
-    data->lasty = 0;
-}
-
 typedef struct _compactpoly {
 typedef struct _compactpoly {
-    gfxcompactpoly_t*poly;
+    gfxpoly_t*poly;
     point_t last;
     int strokes_size;
     point_t*points;
     point_t last;
     int strokes_size;
     point_t*points;
@@ -216,7 +158,7 @@ void finish_segment(compactpoly_t*data)
 #endif
     data->poly->num_strokes++;
 }
 #endif
     data->poly->num_strokes++;
 }
-static void compactmoveto(polywriter_t*w, int x, int y)
+static void compactmoveto(polywriter_t*w, int32_t x, int32_t y)
 {
     compactpoly_t*data = (compactpoly_t*)w->internal;
     point_t p;
 {
     compactpoly_t*data = (compactpoly_t*)w->internal;
     point_t p;
@@ -227,7 +169,7 @@ static void compactmoveto(polywriter_t*w, int x, int y)
     }
     data->last = p;
 }
     }
     data->last = p;
 }
-static void compactlineto(polywriter_t*w, int x, int y)
+static void compactlineto(polywriter_t*w, int32_t x, int32_t y)
 {
     compactpoly_t*data = (compactpoly_t*)w->internal;
     point_t p;
 {
     compactpoly_t*data = (compactpoly_t*)w->internal;
     point_t p;
@@ -271,18 +213,18 @@ static void*compactfinish(polywriter_t*w)
     data->poly->strokes = (gfxpolystroke_t*)rfx_realloc(data->poly->strokes, sizeof(gfxpolystroke_t)*data->poly->num_strokes);
     //qsort(data->poly->strokes, data->poly->num_strokes, sizeof(gfxpolystroke_t), compare_stroke);
     free(data->points);
     data->poly->strokes = (gfxpolystroke_t*)rfx_realloc(data->poly->strokes, sizeof(gfxpolystroke_t)*data->poly->num_strokes);
     //qsort(data->poly->strokes, data->poly->num_strokes, sizeof(gfxpolystroke_t), compare_stroke);
     free(data->points);
-    gfxcompactpoly_t*poly = data->poly;
+    gfxpoly_t*poly = data->poly;
     free(w->internal);w->internal = 0;
     return (void*)poly;
 }
     free(w->internal);w->internal = 0;
     return (void*)poly;
 }
-void gfxcompactpolywriter_init(polywriter_t*w)
+void gfxpolywriter_init(polywriter_t*w)
 {
     w->moveto = compactmoveto;
     w->lineto = compactlineto;
     w->setgridsize = compactsetgridsize;
     w->finish = compactfinish;
     compactpoly_t*data = w->internal = rfx_calloc(sizeof(compactpoly_t));
 {
     w->moveto = compactmoveto;
     w->lineto = compactlineto;
     w->setgridsize = compactsetgridsize;
     w->finish = compactfinish;
     compactpoly_t*data = w->internal = rfx_calloc(sizeof(compactpoly_t));
-    data->poly = rfx_calloc(sizeof(gfxcompactpoly_t));
+    data->poly = rfx_calloc(sizeof(gfxpoly_t));
     data->poly->gridsize = 1.0;
     data->last.x = data->last.y = 0;
     data->strokes_size = 16;
     data->poly->gridsize = 1.0;
     data->last.x = data->last.y = 0;
     data->strokes_size = 16;
@@ -296,60 +238,21 @@ void gfxcompactpolywriter_init(polywriter_t*w)
 
 gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize)
 {
 
 gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize)
 {
-    polywriter_t w;
-    gfxpolywriter_init(&w);
-    w.setgridsize(&w, gridsize);
-    convert_gfxline(line, &w, gridsize);
-    return w.finish(&w);
-}
-gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize)
-{
-    polywriter_t w;
-    gfxpolywriter_init(&w);
-    w.setgridsize(&w, gridsize);
-    convert_file(filename, &w, gridsize);
-    return w.finish(&w);
-}
-gfxcompactpoly_t* gfxcompactpoly_from_gfxline(gfxline_t*line, double gridsize)
-{
     polywriter_t writer;
     polywriter_t writer;
-    gfxcompactpolywriter_init(&writer);
+    gfxpolywriter_init(&writer);
     writer.setgridsize(&writer, gridsize);
     convert_gfxline(line, &writer, gridsize);
     writer.setgridsize(&writer, gridsize);
     convert_gfxline(line, &writer, gridsize);
-    return (gfxcompactpoly_t*)writer.finish(&writer);
+    return (gfxpoly_t*)writer.finish(&writer);
 }
 }
-gfxcompactpoly_t* gfxcompactpoly_from_file(const char*filename, double gridsize)
+gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize)
 {
     polywriter_t writer;
 {
     polywriter_t writer;
-    gfxcompactpolywriter_init(&writer);
+    gfxpolywriter_init(&writer);
     writer.setgridsize(&writer, gridsize);
     convert_file(filename, &writer, gridsize);
     writer.setgridsize(&writer, gridsize);
     convert_file(filename, &writer, gridsize);
-    return (gfxcompactpoly_t*)writer.finish(&writer);
-}
-gfxpoly_t*gfxpoly_from_gfxcompactpoly(gfxcompactpoly_t*poly)
-{
-    int s,t;
-    int pass;
-    gfxpoly_t*poly2 = gfxpoly_new(poly->gridsize);
-    for(t=0;t<poly->num_strokes;t++) {
-       gfxpolystroke_t*stroke = &poly->strokes[t];
-       for(s=0;s<stroke->num_points-1;s++) {
-           point_t a = stroke->points[s];
-           point_t b = stroke->points[s+1];
-           edge_t*e = 0;
-           if(stroke->dir == DIR_UP) {
-               e = edge_new(a.x,a.y,b.x,b.y);
-           } else {
-               e = edge_new(b.x,b.y,a.x,a.y);
-           }
-           e->style = stroke->fs;
-           e->next = poly2->edges;
-           poly2->edges = e;
-       }
-    }
-    return poly2;
+    return (gfxpoly_t*)writer.finish(&writer);
 }
 }
-void gfxcompactpoly_destroy(gfxcompactpoly_t*poly)
+void gfxpoly_destroy(gfxpoly_t*poly)
 {
     int t;
     for(t=0;t<poly->num_strokes;t++) {
 {
     int t;
     for(t=0;t<poly->num_strokes;t++) {
index e5b3545..eec362d 100644 (file)
@@ -4,25 +4,18 @@
 #include "../gfxdevice.h"
 #include "poly.h"
 
 #include "../gfxdevice.h"
 #include "poly.h"
 
-gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize);
-gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize);
-gfxpoly_t* gfxpoly_from_gfxcompactpoly(gfxcompactpoly_t*poly);
-
 typedef struct _polywriter
 {
 typedef struct _polywriter
 {
-    void(*moveto)(struct _polywriter*, int x, int y);
-    void(*lineto)(struct _polywriter*, int x, int y);
+    void(*moveto)(struct _polywriter*, int32_t x, int32_t y);
+    void(*lineto)(struct _polywriter*, int32_t x, int32_t y);
     void(*setgridsize)(struct _polywriter*, double g);
     void*(*finish)(struct _polywriter*);
     void*internal;
 } polywriter_t;
 
 void gfxpolywriter_init(polywriter_t*w);
     void(*setgridsize)(struct _polywriter*, double g);
     void*(*finish)(struct _polywriter*);
     void*internal;
 } polywriter_t;
 
 void gfxpolywriter_init(polywriter_t*w);
-void gfxcompactpolywriter_init(polywriter_t*w);
-
-gfxcompactpoly_t* gfxcompactpoly_from_gfxline(gfxline_t*line, double gridsize);
-gfxcompactpoly_t* gfxcompactpoly_from_file(const char*filename, double gridsize);
-
-void gfxcompactpoly_destroy(gfxcompactpoly_t*poly);
+gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize);
+gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize);
+void gfxpoly_destroy(gfxpoly_t*poly);
 
 #endif //__poly_convert_h__
 
 #endif //__poly_convert_h__
index fad4916..1c9e739 100644 (file)
@@ -11,7 +11,7 @@
 #include "wind.h"
 #include "convert.h"
 
 #include "wind.h"
 #include "convert.h"
 
-static gfxcompactpoly_t*current_polygon = 0;
+static gfxpoly_t*current_polygon = 0;
 void gfxpoly_fail(char*expr, char*file, int line, const char*function)
 {
     if(!current_polygon) {
 void gfxpoly_fail(char*expr, char*file, int line, const char*function)
 {
     if(!current_polygon) {
@@ -38,7 +38,7 @@ void gfxpoly_fail(char*expr, char*file, int line, const char*function)
     fprintf(stderr, "assert(%s) failed in %s in line %d: %s\n", expr, file, line, function);
     fprintf(stderr, "I'm saving a debug file \"%s\" to the current directory.\n", filename);
 
     fprintf(stderr, "assert(%s) failed in %s in line %d: %s\n", expr, file, line, function);
     fprintf(stderr, "I'm saving a debug file \"%s\" to the current directory.\n", filename);
 
-    gfxcompactpoly_save(current_polygon, filename);
+    gfxpoly_save(current_polygon, filename);
     exit(1);
 }
 
     exit(1);
 }
 
@@ -138,34 +138,8 @@ static int compare_events(const void*_a,const void*_b)
     //return d;
 }
 
     //return d;
 }
 
-gfxpoly_t* gfxpoly_new(double gridsize)
-{
-    gfxpoly_t*p = (gfxpoly_t*)rfx_calloc(sizeof(gfxpoly_t));
-    p->gridsize = gridsize;
-    return p;
-}
-void gfxpoly_destroy(gfxpoly_t*poly)
-{
-    edge_t* s = poly->edges;
-    while(s) {
-        edge_t*next  = s->next;
-        free(s);
-        s = next;
-    }
-    free(poly);
-}
 int gfxpoly_size(gfxpoly_t*poly)
 {
 int gfxpoly_size(gfxpoly_t*poly)
 {
-    edge_t*e = poly->edges;
-    int count = 0;
-    while(e) {
-       count++;
-       e = e->next;
-    }
-    return count;
-}
-int gfxcompactpoly_size(gfxcompactpoly_t*poly)
-{
     int s,t;
     int edges = 0;
     for(t=0;t<poly->num_strokes;t++) {
     int s,t;
     int edges = 0;
     for(t=0;t<poly->num_strokes;t++) {
@@ -177,41 +151,6 @@ int gfxcompactpoly_size(gfxcompactpoly_t*poly)
 
 char gfxpoly_check(gfxpoly_t*poly)
 {
 
 char gfxpoly_check(gfxpoly_t*poly)
 {
-    edge_t* s = poly->edges;
-    dict_t*d = dict_new2(&point_type);
-    while(s) {
-        if(!dict_contains(d, &s->a)) {
-            dict_put(d, &s->a, (void*)(ptroff_t)1);
-        } else {
-            int count = (ptroff_t)dict_lookup(d, &s->a);
-            dict_del(d, &s->a);
-            count++;
-            dict_put(d, &s->a, (void*)(ptroff_t)count);
-        }
-        if(!dict_contains(d, &s->b)) {
-            dict_put(d, &s->b, (void*)(ptroff_t)1);
-        } else {
-            int count = (ptroff_t)dict_lookup(d, &s->b);
-            dict_del(d, &s->b);
-            count++;
-            dict_put(d, &s->b, (void*)(ptroff_t)count);
-        }
-        s = s->next;
-    }
-    DICT_ITERATE_ITEMS(d, point_t*, p, void*, c) {
-        int count = (ptroff_t)c;
-        if(count&1) {
-            fprintf(stderr, "Point (%f,%f) occurs %d times\n", p->x*poly->gridsize, p->y*poly->gridsize, count);
-            dict_destroy(d);
-            return 0;
-        }
-    }
-    dict_destroy(d);
-    return 1;
-}
-
-char gfxcompactpoly_check(gfxcompactpoly_t*poly)
-{
     dict_t*d = dict_new2(&point_type);
     int s,t;
     for(t=0;t<poly->num_strokes;t++) {
     dict_t*d = dict_new2(&point_type);
     int s,t;
     for(t=0;t<poly->num_strokes;t++) {
@@ -243,17 +182,6 @@ char gfxcompactpoly_check(gfxcompactpoly_t*poly)
 
 void gfxpoly_dump(gfxpoly_t*poly)
 {
 
 void gfxpoly_dump(gfxpoly_t*poly)
 {
-    edge_t* s = poly->edges;
-    double g = poly->gridsize;
-    fprintf(stderr, "polyon %08x (gridsize: %f)\n", poly, poly->gridsize);
-    while(s) {
-        fprintf(stderr, "(%f,%f) -> (%f,%f)\n", s->a.x*g, s->a.y*g, s->b.x*g, s->b.y*g);
-        s = s->next;
-    }
-}
-
-void gfxcompactpoly_dump(gfxcompactpoly_t*poly)
-{
     int s,t;
     double g = poly->gridsize;
     fprintf(stderr, "polyon %08x (gridsize: %f)\n", poly, poly->gridsize);
     int s,t;
     double g = poly->gridsize;
     fprintf(stderr, "polyon %08x (gridsize: %f)\n", poly, poly->gridsize);
@@ -268,7 +196,7 @@ void gfxcompactpoly_dump(gfxcompactpoly_t*poly)
     }
 }
 
     }
 }
 
-void gfxcompactpoly_save(gfxcompactpoly_t*poly, const char*filename)
+void gfxpoly_save(gfxpoly_t*poly, const char*filename)
 {
     FILE*fi = fopen(filename, "wb");
     fprintf(fi, "%% gridsize %f\n", poly->gridsize);
 {
     FILE*fi = fopen(filename, "wb");
     fprintf(fi, "%% gridsize %f\n", poly->gridsize);
@@ -420,7 +348,7 @@ static void advance_stroke(heap_t*queue, gfxpolystroke_t*stroke, int polygon_nr,
     }
 }
 
     }
 }
 
-static void gfxpoly_enqueue(gfxcompactpoly_t*p, heap_t*queue, int polygon_nr)
+static void gfxpoly_enqueue(gfxpoly_t*p, heap_t*queue, int polygon_nr)
 {
     int t;
     for(t=0;t<p->num_strokes;t++) {
 {
     int t;
     for(t=0;t<p->num_strokes;t++) {
@@ -659,7 +587,6 @@ static inline box_t box_new(int32_t x, int32_t y)
     return box;
 }
 
     return box;
 }
 
-
 static void insert_point_into_segment(status_t*status, segment_t*s, point_t p)
 {
     assert(s->pos.x != p.x || s->pos.y != p.y);
 static void insert_point_into_segment(status_t*status, segment_t*s, point_t p)
 {
     assert(s->pos.x != p.x || s->pos.y != p.y);
@@ -1096,7 +1023,7 @@ static void check_status(status_t*status)
 }
 #endif
 
 }
 #endif
 
-static void add_horizontals(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context)
+static void add_horizontals(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context)
 {
     /*
           |..|        |...........|                 |           |
 {
     /*
           |..|        |...........|                 |           |
@@ -1219,7 +1146,7 @@ static void add_horizontals(gfxcompactpoly_t*poly, windrule_t*windrule, windcont
     heap_destroy(queue);
 }
 
     heap_destroy(queue);
 }
 
-gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context)
+gfxpoly_t* gfxpoly_process(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context)
 {
     current_polygon = poly;
     heap_t* queue = heap_new(sizeof(event_t), compare_events);
 {
     current_polygon = poly;
     heap_t* queue = heap_new(sizeof(event_t), compare_events);
@@ -1232,7 +1159,7 @@ gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windconte
     status.windrule = windrule;
     status.context = context;
     status.actlist = actlist_new();
     status.windrule = windrule;
     status.context = context;
     status.actlist = actlist_new();
-    gfxcompactpolywriter_init(&status.writer);
+    gfxpolywriter_init(&status.writer);
     status.writer.setgridsize(&status.writer, poly->gridsize);
 
 #ifdef CHECKS
     status.writer.setgridsize(&status.writer, poly->gridsize);
 
 #ifdef CHECKS
@@ -1290,10 +1217,8 @@ gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windconte
     heap_destroy(queue);
     xrow_destroy(status.xrow);
 
     heap_destroy(queue);
     xrow_destroy(status.xrow);
 
-    gfxcompactpoly_t*p = (gfxcompactpoly_t*)status.writer.finish(&status.writer);
+    gfxpoly_t*p = (gfxpoly_t*)status.writer.finish(&status.writer);
 
     add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
 
     add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
-    gfxpoly_t*pp = gfxpoly_from_gfxcompactpoly(p);
-    gfxcompactpoly_destroy(p);
-    return pp;
+    return p;
 }
 }
index 7ef125c..5d50209 100644 (file)
@@ -22,16 +22,6 @@ typedef struct _fillstyle {
     char is_filled;
 } fillstyle_t;
 
     char is_filled;
 } fillstyle_t;
 
-typedef struct _edge {
-    point_t a;
-    point_t b;
-    fillstyle_t*style;
-#ifdef DEBUG
-    int tmp;
-#endif
-    struct _edge *next;
-} edge_t;
-
 typedef struct _windstate
 {
     char is_filled;
 typedef struct _windstate
 {
     char is_filled;
@@ -58,12 +48,13 @@ typedef struct _gfxpolystroke {
     int num_points;
     point_t*points;
     fillstyle_t*fs;
     int num_points;
     point_t*points;
     fillstyle_t*fs;
+    struct _gfxpolystroke*next;
 } gfxpolystroke_t;
 } gfxpolystroke_t;
-typedef struct _gfxcompactpoly {
+typedef struct _gfxpoly {
     double gridsize;
     int num_strokes;
     gfxpolystroke_t*strokes;
     double gridsize;
     int num_strokes;
     gfxpolystroke_t*strokes;
-} gfxcompactpoly_t;
+} gfxpoly_t;
 
 typedef struct _segment {
     point_t a;
 
 typedef struct _segment {
     point_t a;
@@ -116,19 +107,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)
 
 #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);
 
 void gfxpoly_fail(char*expr, char*file, int line, const char*function);
 
-gfxpoly_t* gfxpoly_new(double gridsize);
-char gfxcompactpoly_check(gfxcompactpoly_t*poly);
-int gfxcompactpoly_size(gfxcompactpoly_t*poly);
-void gfxcompactpoly_dump(gfxcompactpoly_t*poly);
-void gfxcompactpoly_save(gfxcompactpoly_t*poly, const char*filename);
-gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context);
+char gfxpoly_check(gfxpoly_t*poly);
+int gfxpoly_size(gfxpoly_t*poly);
+void gfxpoly_dump(gfxpoly_t*poly);
+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
 
 #ifndef CHECKS
 #ifdef assert
index c1a428f..2da9c63 100644 (file)
@@ -8,7 +8,6 @@ typedef struct _renderpoint
     double x;
     segment_dir_t dir;
     fillstyle_t*fs;
     double x;
     segment_dir_t dir;
     fillstyle_t*fs;
-    edge_t*e; //only for debugging
     int polygon_nr;
 } renderpoint_t;
 
     int polygon_nr;
 } renderpoint_t;
 
@@ -28,13 +27,12 @@ typedef struct _renderbuf
     renderline_t*lines;
 } renderbuf_t;
 
     renderline_t*lines;
 } renderbuf_t;
 
-static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr, edge_t*e)
+static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr)
 {
     renderpoint_t p;
     p.x = x;
     p.dir = dir;
     p.fs = fs;
 {
     renderpoint_t p;
     p.x = x;
     p.dir = dir;
     p.fs = fs;
-    p.e = e;
     p.polygon_nr = polygon_nr;
     
     if(y >= buf->bbox.ymax || y < buf->bbox.ymin) 
     p.polygon_nr = polygon_nr;
     
     if(y >= buf->bbox.ymax || y < buf->bbox.ymin) 
@@ -50,7 +48,7 @@ static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir
     l->num++;
 }
 #define CUT 0.5
     l->num++;
 }
 #define CUT 0.5
-static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr, edge_t*e)
+static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr)
 {
     x1 *= buf->zoom;
     y1 *= buf->zoom;
 {
     x1 *= buf->zoom;
     y1 *= buf->zoom;
@@ -90,7 +88,7 @@ static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2
 
     while(posy<=endy) {
         double xx = startx + posx;
 
     while(posy<=endy) {
         double xx = startx + posx;
-        add_pixel(buf, xx, posy, dir, fs, polygon_nr, e);
+        add_pixel(buf, xx, posy, dir, fs, polygon_nr);
         posx+=stepx;
         posy++;
     }
         posx+=stepx;
         posy++;
     }
@@ -140,10 +138,15 @@ unsigned char* render_polygon(gfxpoly_t*polygon, intbbox_t*bbox, double zoom, wi
         buf->lines[y].num = 0;
     }
 
         buf->lines[y].num = 0;
     }
 
-    edge_t*e;
     int polygon_nr = 0;
     int polygon_nr = 0;
-    for(e=polygon->edges;e;e=e->next) {
-        add_line(buf, e->a.x, e->a.y, e->b.x, e->b.y, e->style, polygon_nr, e);
+    int s,t;
+    for(s=0;s<polygon->num_strokes;s++) {
+       gfxpolystroke_t*stroke = &polygon->strokes[s];
+       for(t=0;t<stroke->num_points-1;t++) {
+           point_t a = stroke->points[t];
+           point_t b = stroke->points[t+1];
+           add_line(buf, a.x, a.y, b.x, b.y, stroke->fs, polygon_nr);
+       }
     }
 
     for(y=0;y<buf->height;y++) {
     }
 
     for(y=0;y<buf->height;y++) {
@@ -221,31 +224,30 @@ intbbox_t intbbox_new(int x1, int y1, int x2, int y2)
 
 intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom)
 {
 
 intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom)
 {
-    int t;
     intbbox_t b = {0,0,0,0};
     intbbox_t b = {0,0,0,0};
-    edge_t*e = polygon->edges;
 
     double g = zoom*polygon->gridsize;
 
 
     double g = zoom*polygon->gridsize;
 
-    if(e) {
-        b.xmin = e->a.x*g;
-        b.ymin = e->a.y*g;
-        b.xmax = e->a.x*g;
-        b.ymax = e->a.y*g;
+    if(polygon->num_strokes && polygon->strokes[0].num_points) {
+        b.xmin = polygon->strokes[0].points[0].x*g;
+        b.ymin = polygon->strokes[0].points[0].y*g;
+        b.xmax = polygon->strokes[0].points[0].x*g;
+        b.ymax = polygon->strokes[0].points[0].y*g;
     }
     }
-    for(e=polygon->edges;e;e=e->next) {
-        double x_min = min(e->a.x,e->b.x)*g;
-        double y_min = min(e->a.y,e->b.y)*g;
-        double x_max = max(e->a.x,e->b.x)*g;
-        double y_max = max(e->a.y,e->b.y)*g;
-        int x1 = floor(x_min);
-        int y1 = floor(y_min);
-        int x2 = ceil(x_max);
-        int y2 = ceil(y_max);
-        if(x1 < b.xmin) b.xmin = x1;
-        if(y1 < b.ymin) b.ymin = y1;
-        if(x2 > b.xmax) b.xmax = x2;
-        if(y2 > b.ymax) b.ymax = y2;
+    int s,t;
+    for(s=0;s<polygon->num_strokes;s++) {
+       gfxpolystroke_t*stroke = &polygon->strokes[s];
+       for(t=0;t<stroke->num_points;t++) {
+           point_t p = stroke->points[t];
+           int x1 = floor(p.x);
+           int y1 = floor(p.y);
+           int x2 = ceil(p.x);
+           int y2 = ceil(p.y);
+           if(x1 < b.xmin) b.xmin = x1;
+           if(y1 < b.ymin) b.ymin = y1;
+           if(x2 > b.xmax) b.xmax = x2;
+           if(y2 > b.ymax) b.ymax = y2;
+       }
     }
     
     if(b.xmax > (int)(MAX_WIDTH*zoom))
     }
     
     if(b.xmax > (int)(MAX_WIDTH*zoom))
index c67f193..a04f779 100644 (file)
@@ -138,7 +138,7 @@ int test_speed()
 {
     //gfxline_t* b = mkchessboard();
     //gfxline_t* b = mkrandomshape(100,7);
 {
     //gfxline_t* b = mkchessboard();
     //gfxline_t* b = mkrandomshape(100,7);
-    gfxline_t* b = make_circles(30);
+    gfxline_t* b = make_circles(100);
 
     gfxmatrix_t m;
     memset(&m, 0, sizeof(gfxmatrix_t));
 
     gfxmatrix_t m;
     memset(&m, 0, sizeof(gfxmatrix_t));
@@ -153,10 +153,10 @@ int test_speed()
        m.ty = 400*1.41/2;
        gfxline_t*l = gfxline_clone(b);
        gfxline_transform(l, &m);
        m.ty = 400*1.41/2;
        gfxline_t*l = gfxline_clone(b);
        gfxline_transform(l, &m);
-       gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(b, 0.05);
+       gfxpoly_t*poly = gfxpoly_from_gfxline(b, 0.05);
 
        gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
 
        gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
-       gfxcompactpoly_destroy(poly);
+       gfxpoly_destroy(poly);
        gfxpoly_destroy(poly2);
        gfxline_free(l);
     }
        gfxpoly_destroy(poly2);
        gfxline_free(l);
     }
@@ -184,38 +184,18 @@ int test1(int argn, char*argv[])
 
     gfxline_dump(b, stderr, "");
 
 
     gfxline_dump(b, stderr, "");
 
-    gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(b, 0.05);
+    gfxpoly_t*poly = gfxpoly_from_gfxline(b, 0.05);
     gfxline_free(box1);
     gfxline_free(box2);
     gfxline_free(box3);
     gfxline_free(star);
 
     gfxline_free(box1);
     gfxline_free(box2);
     gfxline_free(box3);
     gfxline_free(star);
 
-    gfxcompactpoly_dump(poly);
+    gfxpoly_dump(poly);
     gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
     gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
-    gfxcompactpoly_destroy(poly);
+    gfxpoly_destroy(poly);
     gfxpoly_destroy(poly2);
 }
 
     gfxpoly_destroy(poly2);
 }
 
-static void test_conversion(gfxline_t*line, double gridsize)
-{
-    double zoom=1.0;
-    gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, gridsize);
-    gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, gridsize);
-    gfxpoly_t*poly2 = gfxpoly_from_gfxcompactpoly(poly);
-    assert(gfxpoly_check(poly1));
-    assert(gfxpoly_check(poly2));
-    assert(gfxcompactpoly_check(poly));
-    intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
-    unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, &windrule_evenodd, &onepolygon);
-    assert(bitmap_ok(&bbox, bitmap1));
-    unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
-    assert(bitmap_ok(&bbox, bitmap2));
-    if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
-       save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
-       assert(!"bitmaps don't match");
-    }
-}
-
 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
 {
     int t;
 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
 {
     int t;
@@ -230,14 +210,11 @@ int test_square(int width, int height, int num, double gridsize, char bitmaptest
     line[num-1].y = line[0].y;
     line[num-1].next = 0;
 
     line[num-1].y = line[0].y;
     line[num-1].next = 0;
 
-    test_conversion(line, gridsize);
-    
-    gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, gridsize);
+    gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, gridsize);
     gfxline_free(line);
     gfxline_free(line);
-    gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
 
     windrule_t*rule = &windrule_circular;
 
     windrule_t*rule = &windrule_circular;
-    gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+    gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
     if(bitmaptest) {
         intbbox_t bbox = intbbox_new(0, 0, width, height);
         unsigned char*bitmap1 = render_polygon(poly1, &bbox, 1.0, rule, &onepolygon);
     if(bitmaptest) {
         intbbox_t bbox = intbbox_new(0, 0, width, height);
         unsigned char*bitmap1 = render_polygon(poly1, &bbox, 1.0, rule, &onepolygon);
@@ -251,7 +228,6 @@ int test_square(int width, int height, int num, double gridsize, char bitmaptest
     }
     gfxpoly_destroy(poly1);
     gfxpoly_destroy(poly2);
     }
     gfxpoly_destroy(poly1);
     gfxpoly_destroy(poly2);
-    gfxcompactpoly_destroy(poly);
 }
 
 int test2(int argn, char*argv[])
 }
 
 int test2(int argn, char*argv[])
@@ -310,10 +286,8 @@ void test3(int argn, char*argv[])
         gfxline_t*l = gfxline_clone(line);
         gfxline_transform(l, &m);
 
         gfxline_t*l = gfxline_clone(line);
         gfxline_transform(l, &m);
 
-       test_conversion(l, 0.05);
-        
-        gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(l, 0.05);
-        gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+        gfxpoly_t*poly1 = gfxpoly_from_gfxline(l, 0.05);
+        gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
 
         tag = swf_InsertTag(tag, ST_DEFINESHAPE);
         SHAPE* s;
 
         tag = swf_InsertTag(tag, ST_DEFINESHAPE);
         SHAPE* s;
@@ -330,18 +304,23 @@ void test3(int argn, char*argv[])
 #define FILL
 #ifdef FILL
         swf_ShapeSetAll(tag,s,0,0,0,fs,0);
 #define FILL
 #ifdef FILL
         swf_ShapeSetAll(tag,s,0,0,0,fs,0);
-        edge_t*e = poly2->edges;
-        while(e) {
+
+       int i,j;
+       for(i=0;i<poly2->num_strokes;i++) {
+           gfxpolystroke_t*stroke = &poly2->strokes[i];
+           for(j=0;j<stroke->num_points-1;j++) {
+               point_t a = stroke->points[j];
+               point_t b = stroke->points[j+1];
 #define ROTATE
 #ifdef ROTATE
 #define ROTATE
 #ifdef ROTATE
-            swf_ShapeSetMove(tag, s, e->a.y, e->a.x);
-            swf_ShapeSetLine(tag, s, e->b.y - e->a.y, e->b.x - e->a.x);
+               swf_ShapeSetMove(tag, s, a.y, a.x);
+               swf_ShapeSetLine(tag, s, b.y - a.y, b.x - a.x);
 #else
 #else
-            swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
-            swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
+               swf_ShapeSetMove(tag, s, a.x, a.y);
+               swf_ShapeSetLine(tag, s, b.x - a.x, b.y - a.y);
 #endif
 #endif
-            e = e->next;
-        }
+           }
+       }
 #else
         swf_ShapeSetAll(tag,s,0,0,ls,0,0);
         edge_t*e = poly2->edges;
 #else
         swf_ShapeSetAll(tag,s,0,0,ls,0,0);
         edge_t*e = poly2->edges;
@@ -358,7 +337,7 @@ void test3(int argn, char*argv[])
         swf_ShapeSetEnd(tag);
         swf_ShapeFree(s);
 
         swf_ShapeSetEnd(tag);
         swf_ShapeFree(s);
 
-        gfxcompactpoly_destroy(poly);
+        gfxpoly_destroy(poly1);
         gfxpoly_destroy(poly2);
 
         gfxline_free(l);
         gfxpoly_destroy(poly2);
 
         gfxline_free(l);
@@ -379,15 +358,14 @@ void test3(int argn, char*argv[])
 
 void rotate90(gfxpoly_t*poly)
 {
 
 void rotate90(gfxpoly_t*poly)
 {
-    edge_t*e = poly->edges;
-    while(e) {
-       point_t a = e->a;
-       point_t b = e->b;
-       e->a.x = a.y;
-       e->a.y = a.x;
-       e->b.x = b.y;
-       e->b.y = b.x;
-       e = e->next;
+    int i,j;
+    for(i=0;i<poly->num_strokes;i++) {
+       gfxpolystroke_t*stroke = &poly->strokes[i];
+       for(j=0;j<stroke->num_points;j++) {
+           point_t a = stroke->points[j];
+           stroke->points[j].x = a.y;
+           stroke->points[j].y = a.x;
+       }
     }
 }
 
     }
 }
 
@@ -413,20 +391,19 @@ void test4(int argn, char*argv[])
             filename = argv[1];
 
         windrule_t*rule = &windrule_evenodd;
             filename = argv[1];
 
         windrule_t*rule = &windrule_evenodd;
-        gfxcompactpoly_t*poly = gfxcompactpoly_from_file(filename, 1.0);//0.01);
+        gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01);
 
         if(argn!=2)
             free(filename);
 
         double zoom = 1.0;
 
 
         if(argn!=2)
             free(filename);
 
         double zoom = 1.0;
 
-        if(!gfxcompactpoly_check(poly)) {
+        if(!gfxpoly_check(poly1)) {
             printf("bad polygon\n");
             continue;
         }
 
             printf("bad polygon\n");
             continue;
         }
 
-       gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
-        gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+        gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
 
        int pass;
        for(pass=0;pass<2;pass++) {
 
        int pass;
        for(pass=0;pass<2;pass++) {
@@ -451,7 +428,6 @@ void test4(int argn, char*argv[])
 
         gfxpoly_destroy(poly1);
         gfxpoly_destroy(poly2);
 
         gfxpoly_destroy(poly1);
         gfxpoly_destroy(poly2);
-        gfxcompactpoly_destroy(poly);
         if(argn==2) 
             break;
     }
         if(argn==2) 
             break;
     }
@@ -463,31 +439,29 @@ void test4(int argn, char*argv[])
 
 void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) 
 {
 
 void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color) 
 {
-    //gfxcompactpoly_t*c = gfxcompactpoly_from_gfxline(line, 0.05);
-    //gfxcompactpoly_free(c);
+    //gfxpoly_t*c = gfxpoly_from_gfxline(line, 0.05);
+    //gfxpoly_free(c);
 
 
-    gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, 0.05);
+    gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, 0.05);
 
     //gfxline_dump(line, stderr, "");
 
     //gfxline_dump(line, stderr, "");
-    //gfxcompactpoly_dump(poly);
+    //gfxpoly_dump(poly);
 
 
-    if(gfxcompactpoly_size(poly)>100000) {
-       fprintf(stderr, "%d segments (skipping)\n", gfxcompactpoly_size(poly));
+    if(gfxpoly_size(poly1)>100000) {
+       fprintf(stderr, "%d segments (skipping)\n", gfxpoly_size(poly1));
        return;
     } else {
        //fprintf(stderr, "%d segments\n", gfxpoly_size(poly));
     }
 
        return;
     } else {
        //fprintf(stderr, "%d segments\n", gfxpoly_size(poly));
     }
 
-    if(!gfxcompactpoly_check(poly)) {
-        gfxcompactpoly_destroy(poly);
+    if(!gfxpoly_check(poly1)) {
+        gfxpoly_destroy(poly1);
         fprintf(stderr, "bad polygon\n");
         return;
     }
 
     windrule_t*rule = &windrule_evenodd;
 
         fprintf(stderr, "bad polygon\n");
         return;
     }
 
     windrule_t*rule = &windrule_evenodd;
 
-    gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
-        
     double zoom = 1.0;
     intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
     unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
     double zoom = 1.0;
     intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
     unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
@@ -495,7 +469,7 @@ void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
         fprintf(stderr, "bad polygon or error in renderer\n");
         return;
     }
         fprintf(stderr, "bad polygon or error in renderer\n");
         return;
     }
-    gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+    gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
     unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
     if(!bitmap_ok(&bbox, bitmap2)) {
         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
     unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
     if(!bitmap_ok(&bbox, bitmap2)) {
         save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
@@ -510,7 +484,6 @@ void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
 
     gfxpoly_destroy(poly1);
     gfxpoly_destroy(poly2);
 
     gfxpoly_destroy(poly1);
     gfxpoly_destroy(poly2);
-    gfxcompactpoly_destroy(poly);
 }
 int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) {
     return 0;
 }
 int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) {
     return 0;
@@ -606,6 +579,6 @@ void test5(int argn, char*argv[])
 
 int main(int argn, char*argv[])
 {
 
 int main(int argn, char*argv[])
 {
-    test_speed(argn, argv);
+    test4(argn, argv);
 }
 
 }