many optimizations and bugfixes in the new intersector code
[swftools.git] / lib / gfxpoly / test.c
index e4e8455..e8c140c 100644 (file)
@@ -11,12 +11,12 @@ gfxline_t*mkstar(int x1, int y1, int x2, int y2)
     gfxline_t*l=0,*line = 0;
     int x;
     for(x=x1;x<=x2;x+=50) {
-        l = malloc(sizeof(gfxline_t));
+        l = rfx_calloc(sizeof(gfxline_t));
         l->type = gfx_moveTo;
         l->x = x;l->y = y1;
         line = gfxline_append(line, l);
 
-        l = malloc(sizeof(gfxline_t));
+        l = rfx_calloc(sizeof(gfxline_t));
         l->type = gfx_lineTo;
         l->x = x2-x;l->y = y2;
         line = gfxline_append(line, l);
@@ -27,7 +27,6 @@ gfxline_t*mkstar(int x1, int y1, int x2, int y2)
 int test1()
 {
     gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
-
     // put box2 and box3 on top of each other *snicker*
     gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
     gfxline_t*box3 = gfxline_makerectangle(100,100,200,200);
@@ -49,6 +48,7 @@ int test1()
     gfxline_free(box1);
     gfxline_free(box2);
     gfxline_free(box3);
+    gfxline_free(star);
 
     gfxpoly_dump(poly);
     gfxpoly_process(poly);
@@ -56,13 +56,14 @@ int test1()
 
 int test2()
 {
-#define N 1000
+#define N 50
+#define RANGE 150
     int t;
     gfxline_t* line = malloc(sizeof(gfxline_t)*N);
     for(t=0;t<N;t++) {
         line[t].type = t?gfx_lineTo:gfx_moveTo;
-        line[t].x = lrand48()%65536;
-        line[t].y = lrand48()%65536;
+        line[t].x = (lrand48()%RANGE)-RANGE/2;
+        line[t].y = (lrand48()%RANGE)-RANGE/2;
         line[t].next = &line[t+1];
     }
     line[N-1].x = line[0].x;
@@ -70,12 +71,100 @@ int test2()
     line[N-1].next = 0;
     
     gfxpoly_t*poly = gfxpoly_fillToPoly(line);
-    gfxpoly_dump(poly);
-    gfxpoly_process(poly);
+    gfxpoly_t*poly2 = gfxpoly_process(poly);
     gfxline_free(line);
+    gfxpoly_destroy(poly);
+    gfxpoly_destroy(poly2);
+}
+
+#include "../rfxswf.h"
+void test3()
+{
+#undef N
+#undef RANGE
+#define N 250
+#define RANGE 150
+
+    int i;
+    gfxline_t* line = malloc(sizeof(gfxline_t)*N);
+    for(i=0;i<N;i++) {
+        line[i].type = i?gfx_lineTo:gfx_moveTo;
+        line[i].x = lrand48()%RANGE - RANGE/2;
+        line[i].y = lrand48()%RANGE - RANGE/2;
+        line[i].next = &line[i+1];
+    }
+    line[N-1].x = line[0].x;
+    line[N-1].y = line[0].y;
+    line[N-1].next = 0;
+
+    gfxmatrix_t m;
+    memset(&m, 0, sizeof(m));
+
+    SWF swf;
+    memset(&swf, 0, sizeof(SWF));
+    swf.movieSize.xmax = RANGE*20*1.41;
+    swf.movieSize.ymax = RANGE*20*1.41;
+    swf.fileVersion = 9;
+    swf.frameRate = 25*0x100;
+    TAG * tag = swf.firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
+    swf_SetU8(tag, 0);
+    swf_SetU8(tag, 0);
+    swf_SetU8(tag, 0);
+
+    int t;
+    for(t=0;t<360;t++) {
+        m.m00 = cos(t*M_PI/180.0);
+        m.m01 = sin(t*M_PI/180.0);
+        m.m10 = -sin(t*M_PI/180.0);
+        m.m11 = cos(t*M_PI/180.0);
+        m.tx = RANGE*1.41/2;
+        m.ty = RANGE*1.41/2;
+        gfxline_t*l = gfxline_clone(line);
+        gfxline_transform(l, &m);
+        
+        gfxpoly_t*poly = gfxpoly_fillToPoly(l);
+        gfxpoly_t*poly2 = gfxpoly_process(poly);
+
+        tag = swf_InsertTag(tag, ST_DEFINESHAPE);
+        SHAPE* s;
+        swf_ShapeNew(&s);
+        RGBA rgb;
+        rgb.r = rgb.g = 0x00; rgb.b = 0xff;
+        rgb.a = 255;
+        int j = swf_ShapeAddSolidFillStyle(s,&rgb);
+        swf_SetU16(tag,t+1);
+        swf_SetRect(tag,&swf.movieSize);
+        swf_SetShapeHeader(tag,s);
+        swf_ShapeSetAll(tag,s,0,0,0,j,0);
+        edge_t*e = poly2;
+        while(e) {
+            swf_ShapeSetMove(tag, s, e->a.x*20, e->a.y*20);
+            swf_ShapeSetLine(tag, s, e->b.x*20 - e->a.x*20, e->b.y*20 - e->a.y*20);
+            e = e->next;
+        }
+        swf_ShapeSetEnd(tag);
+        swf_ShapeFree(s);
+
+        gfxpoly_destroy(poly);
+        gfxpoly_destroy(poly2);
+
+        gfxline_free(l);
+   
+        if(t) {
+            tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
+            swf_SetU16(tag, t);
+        }
+        tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
+        swf_ObjectPlace(tag,t+1,t+1,NULL,NULL,NULL);
+
+        tag = swf_InsertTag(tag, ST_SHOWFRAME);
+    }
+    tag = swf_InsertTag(tag, ST_END);
+
+    swf_SaveSWF(&swf, "test.swf");
 }
 
 int main()
 {
-    test2();
+    test3();
 }