X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Ftest.c;h=6e698ca2b874d5a2ea5453f94f4d9c6019796b85;hp=766b1a7901a1d9a5a0813bc4d74d51bcdf2c4260;hb=bf04757cd94e94c1f67fa3d2a4e3e59fa5bce0c0;hpb=163bdd5cab1758e4517e8365b3e40b5461d63640 diff --git a/lib/gfxpoly/test.c b/lib/gfxpoly/test.c index 766b1a7..6e698ca 100644 --- a/lib/gfxpoly/test.c +++ b/lib/gfxpoly/test.c @@ -1,10 +1,12 @@ #include #include +#include #include #include #include "../gfxtools.h" #include "poly.h" #include "convert.h" +#include "renderpoly.h" gfxline_t*mkstar(int x1, int y1, int x2, int y2) { @@ -35,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)); @@ -43,45 +45,60 @@ int test1() matrix.m00=cos(ua);matrix.m10=sin(ua); matrix.m01=-sin(ua);matrix.m11=cos(ua); - gfxline_transform(b, &matrix); - gfxpoly_t*poly = gfxpoly_fillToPoly(b); + //gfxline_transform(b, &matrix); + gfxpoly_t*poly = gfxpoly_fillToPoly(b, 0.05); gfxline_free(box1); gfxline_free(box2); gfxline_free(box3); gfxline_free(star); gfxpoly_dump(poly); - gfxpoly_process(poly); + gfxpoly_process(poly, &windrule_evenodd); } -int test_square(int width, int height, int num) +int test_square(int width, int height, int num, double gridsize, char bitmaptest) { int t; gfxline_t* line = malloc(sizeof(gfxline_t)*num); for(t=0;tedges; 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); +#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 swf_ShapeSetAll(tag,s,0,0,ls,0,0); - edge_t*e = poly2; + edge_t*e = poly2->edges; 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); + 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_ShapeSetCircle(tag, s, e->a.x*20, e->a.y*20, 5*20, 5*20); - swf_ShapeSetCircle(tag, s, e->b.x*20, e->b.y*20, 5*20, 5*20); + swf_ShapeSetCircle(tag, s, e->a.x, e->a.y, 5*20, 5*20); + swf_ShapeSetCircle(tag, s, e->b.x, e->b.y, 5*20, 5*20); e = e->next; } #endif @@ -190,7 +217,49 @@ void test3() swf_SaveSWF(&swf, "test.swf"); } +#include +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() { - test2(); + test3(); }