many optimizations and bugfixes in the new intersector code
[swftools.git] / lib / gfxpoly / convert.c
index 10171f2..f71a096 100644 (file)
@@ -4,21 +4,33 @@
 #include "../gfxdevice.h"
 #include "poly.h"
 
-static inline void gfxpoly_add_segment(segment_t**list, double _x1, double _y1, double _x2, double _y2)
+static edge_t*edge_new(int x1, int y1, int x2, int y2)
+{
+    edge_t*s = malloc(sizeof(edge_t));
+    s->a.x = x1;
+    s->a.y = y1;
+    s->b.x = x2;
+    s->b.y = y2;
+    s->next = 0;
+    return s;
+}
+
+static inline void gfxpoly_add_edge(edge_t**list, double _x1, double _y1, double _x2, double _y2)
 {
     int x1 = ceil(_x1);
     int y1 = ceil(_y1);
     int x2 = ceil(_x2);
     int y2 = ceil(_y2);
     if(y1!=y2) {
-        segment_t*s = segment_new(x1, y1, x2, y2);
-        segment_insert_before(list, s);
+        edge_t*s = edge_new(x1, y1, x2, y2);
+        s->next = *list;
+        *list = s;
     }
 }
 
 gfxpoly_t* gfxpoly_fillToPoly(gfxline_t*line)
 {
-    segment_t*s = 0;
+    edge_t*s = 0;
 
     /* factor that determines into how many line fragments a spline is converted */
     double subfraction = 2.4;//0.3
@@ -28,7 +40,7 @@ gfxpoly_t* gfxpoly_fillToPoly(gfxline_t*line)
     while(line) {
         if(line->type == gfx_moveTo) {
         } else if(line->type == gfx_lineTo) {
-            gfxpoly_add_segment(&s, lastx, lasty, line->x, line->y);
+            gfxpoly_add_edge(&s, lastx, lasty, line->x, line->y);
        } else if(line->type == gfx_splineTo) {
             int parts = (int)(sqrt(fabs(line->x-2*line->sx+lastx) + 
                                    fabs(line->y-2*line->sy+lasty))*subfraction);
@@ -39,11 +51,11 @@ gfxpoly_t* gfxpoly_fillToPoly(gfxline_t*line)
                double t = (double)i*stepsize;
                double x = line->x*t*t + 2*line->sx*t*(1-t) + x*(1-t)*(1-t);
                double y = line->y*t*t + 2*line->sy*t*(1-t) + y*(1-t)*(1-t);
-                gfxpoly_add_segment(&s, lastx, lasty, x, y);
+                gfxpoly_add_edge(&s, lastx, lasty, x, y);
                 lastx = x;
                 lasty = y;
            }
-            gfxpoly_add_segment(&s, lastx, lasty, line->x, line->y);
+            gfxpoly_add_edge(&s, lastx, lasty, line->x, line->y);
         }
         lastx = line->x;
         lasty = line->y;