polygon intersector: added horizontal line reconstruction
[swftools.git] / lib / gfxpoly / test.c
index b9062f5..6e698ca 100644 (file)
@@ -37,7 +37,7 @@ int test1()
     b = gfxline_append(b, box1);
     b = gfxline_append(b, box2);
     b = gfxline_append(b, box3);
-    b = gfxline_append(b, star);
+    //b = gfxline_append(b, star);
 
     gfxmatrix_t matrix;
     memset(&matrix, 0, sizeof(gfxmatrix_t));
@@ -45,7 +45,7 @@ int test1()
     matrix.m00=cos(ua);matrix.m10=sin(ua);
     matrix.m01=-sin(ua);matrix.m11=cos(ua);
 
-    gfxline_transform(b, &matrix);
+    //gfxline_transform(b, &matrix);
     gfxpoly_t*poly = gfxpoly_fillToPoly(b, 0.05);
     gfxline_free(box1);
     gfxline_free(box2);
@@ -70,12 +70,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;
     
-    windrule_t*rule = &windrule_circular;
-    
     gfxpoly_t*poly = gfxpoly_fillToPoly(line, gridsize);
-    gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
     gfxline_free(line);
 
+    windrule_t*rule = &windrule_circular;
+    gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
     if(bitmaptest) {
         intbbox_t bbox = intbbox_new(0, 0, width, height);
         unsigned char*bitmap1 = render_polygon(poly, &bbox, 1.0, rule);
@@ -85,9 +84,8 @@ int test_square(int width, int height, int num, double gridsize, char bitmaptest
             assert(!"bitmaps don't match");
         }
     }
-
-    gfxpoly_destroy(poly);
     gfxpoly_destroy(poly2);
+    gfxpoly_destroy(poly);
 }
 
 int test2()
@@ -174,8 +172,14 @@ void test3()
         swf_ShapeSetAll(tag,s,0,0,0,fs,0);
         edge_t*e = poly2->edges;
         while(e) {
+#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);
+#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);
+#endif
             e = e->next;
         }
 #else
@@ -213,6 +217,48 @@ void test3()
     swf_SaveSWF(&swf, "test.swf");
 }
 
+#include <dirent.h>
+void test4()
+{
+    char*dir = "ps";
+    DIR*_dir = opendir(dir);
+    if(!_dir) return;
+    struct dirent*file;
+    while(1) {
+        file = readdir(_dir);
+        if (!file) 
+            break;
+        if(!strstr(file->d_name, ".ps")) 
+            continue;
+
+        char* filename = allocprintf("%s/%s", dir, file->d_name);
+        windrule_t*rule = &windrule_evenodd;
+        gfxpoly_t*poly = gfxpoly_from_file(filename, 0.01);
+        free(filename);
+
+        double zoom = 1.0;
+        intbbox_t bbox = intbbox_from_polygon(poly, zoom);
+
+        if(!gfxpoly_check(poly)) {
+            printf("bad polygon\n");
+            continue;
+        }
+
+        gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
+        unsigned char*bitmap1 = render_polygon(poly, &bbox, zoom, rule);
+        unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd);
+        if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) {
+            save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+            assert(!"error in bitmaps");
+        }
+        if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
+            save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
+            assert(!"bitmaps don't match");
+        }
+        gfxpoly_destroy(poly2);
+    }
+}
+
 int main()
 {
     test3();