X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fgfxpoly%2Ftest.c;h=74c6497b81440e50cc476b185cc506bfc5b5ca68;hp=e4e845596950e4370f472135d17ed508531dde14;hb=c41f4433d3e721073c60d55cd923a087761e45f7;hpb=66a03382aab040571f94b0861719753bda3ff8f1 diff --git a/lib/gfxpoly/test.c b/lib/gfxpoly/test.c index e4e8455..74c6497 100644 --- a/lib/gfxpoly/test.c +++ b/lib/gfxpoly/test.c @@ -1,22 +1,24 @@ #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) { 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 +29,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); @@ -45,37 +46,214 @@ int test1() matrix.m01=-sin(ua);matrix.m11=cos(ua); gfxline_transform(b, &matrix); - gfxpoly_t*poly = gfxpoly_fillToPoly(b); + 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 test2() +int test_square(int width, int height, int num, double gridsize, char bitmaptest) { -#define N 1000 int t; - gfxline_t* line = malloc(sizeof(gfxline_t)*N); - for(t=0;tedges; + while(e) { + 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); + e = e->next; + } +#else + swf_ShapeSetAll(tag,s,0,0,ls,0,0); + edge_t*e = poly2->edges; + while(e) { + 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, 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 + + 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"); +} + +#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(); + test4(); }