6 #include "../gfxtools.h"
9 #include "renderpoly.h"
11 gfxline_t*mkstar(int x1, int y1, int x2, int y2)
13 gfxline_t*l=0,*line = 0;
15 for(x=x1;x<=x2;x+=50) {
16 l = rfx_calloc(sizeof(gfxline_t));
19 line = gfxline_append(line, l);
21 l = rfx_calloc(sizeof(gfxline_t));
23 l->x = x2-x;l->y = y2;
24 line = gfxline_append(line, l);
31 gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
32 // put box2 and box3 on top of each other *snicker*
33 gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
34 gfxline_t*box3 = gfxline_makerectangle(100,100,200,200);
35 gfxline_t*star = mkstar(50,50, 150,150);
37 b = gfxline_append(b, box1);
38 b = gfxline_append(b, box2);
39 b = gfxline_append(b, box3);
40 b = gfxline_append(b, star);
43 memset(&matrix, 0, sizeof(gfxmatrix_t));
45 matrix.m00=cos(ua);matrix.m10=sin(ua);
46 matrix.m01=-sin(ua);matrix.m11=cos(ua);
48 gfxline_transform(b, &matrix);
49 gfxpoly_t*poly = gfxpoly_fillToPoly(b, 0.05);
56 gfxpoly_process(poly, &windrule_evenodd);
59 int test_square(int width, int height, int num, double gridsize, char bitmaptest)
62 gfxline_t* line = malloc(sizeof(gfxline_t)*num);
64 line[t].type = t?gfx_lineTo:gfx_moveTo;
65 line[t].x = (lrand48()%width);
66 line[t].y = (lrand48()%height);
67 line[t].next = &line[t+1];
69 line[num-1].x = line[0].x;
70 line[num-1].y = line[0].y;
73 gfxpoly_t*poly = gfxpoly_fillToPoly(line, gridsize);
76 windrule_t*rule = &windrule_circular;
77 gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
79 intbbox_t bbox = intbbox_new(0, 0, width, height);
80 unsigned char*bitmap1 = render_polygon(poly, &bbox, 1.0, rule);
81 unsigned char*bitmap2 = render_polygon(poly2, &bbox, 1.0, &windrule_evenodd);
82 if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
83 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
84 assert(!"bitmaps don't match");
87 gfxpoly_destroy(poly2);
88 gfxpoly_destroy(poly);
93 test_square(400,400, 3, 0.05, 1);
97 test_square(400,400, 50, 0.05, 1);
98 test_square(200,3, 1000, 1.0, 0);
99 test_square(3,200, 1000, 1.0, 0);
100 test_square(10,10, 200, 1.0, 0);
104 #include "../rfxswf.h"
113 gfxline_t* line = malloc(sizeof(gfxline_t)*N*2);
115 line[i].type = i?gfx_lineTo:gfx_moveTo;
116 line[i].x = lrand48()%RANGE - RANGE/2;
117 line[i].y = lrand48()%RANGE - RANGE/2;
118 line[i].next = &line[i+1];
119 line[N*2-i-1].type = gfx_lineTo;
120 line[N*2-i-1].x = line[i].x;
121 line[N*2-i-1].y = line[i].y;
122 line[N*2-i-1].next = &line[N*2-i];
124 line[N*2-1].next = 0;
126 line[N-1].x = line[0].x;
127 line[N-1].y = line[0].y;
131 memset(&m, 0, sizeof(m));
134 memset(&swf, 0, sizeof(SWF));
135 swf.movieSize.xmax = RANGE*20*1.41;
136 swf.movieSize.ymax = RANGE*20*1.41;
138 swf.frameRate = 25*0x100;
139 TAG * tag = swf.firstTag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
146 m.m00 = cos(t*M_PI/180.0);
147 m.m01 = sin(t*M_PI/180.0);
148 m.m10 = -sin(t*M_PI/180.0);
149 m.m11 = cos(t*M_PI/180.0);
152 gfxline_t*l = gfxline_clone(line);
153 gfxline_transform(l, &m);
155 gfxpoly_t*poly = gfxpoly_fillToPoly(l, 0.05);
156 gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_circular);
158 tag = swf_InsertTag(tag, ST_DEFINESHAPE);
162 rgb.r = rgb.g = 0x00; rgb.b = 0xff;
164 int fs = swf_ShapeAddSolidFillStyle(s,&rgb);
165 int ls = swf_ShapeAddLineStyle(s,20,&rgb);
167 swf_SetRect(tag,&swf.movieSize);
168 swf_SetShapeHeader(tag,s);
172 swf_ShapeSetAll(tag,s,0,0,0,fs,0);
173 edge_t*e = poly2->edges;
175 swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
176 swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
180 swf_ShapeSetAll(tag,s,0,0,ls,0,0);
181 edge_t*e = poly2->edges;
183 swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
184 swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
186 swf_ShapeSetCircle(tag, s, e->a.x, e->a.y, 5*20, 5*20);
187 swf_ShapeSetCircle(tag, s, e->b.x, e->b.y, 5*20, 5*20);
192 swf_ShapeSetEnd(tag);
195 gfxpoly_destroy(poly);
196 gfxpoly_destroy(poly2);
201 tag = swf_InsertTag(tag,ST_REMOVEOBJECT2);
204 tag = swf_InsertTag(tag,ST_PLACEOBJECT2);
205 swf_ObjectPlace(tag,t+1,t+1,NULL,NULL,NULL);
207 tag = swf_InsertTag(tag, ST_SHOWFRAME);
209 tag = swf_InsertTag(tag, ST_END);
211 swf_SaveSWF(&swf, "test.swf");
218 DIR*_dir = opendir(dir);
222 file = readdir(_dir);
225 if(!strstr(file->d_name, ".ps"))
228 char* filename = allocprintf("%s/%s", dir, file->d_name);
229 windrule_t*rule = &windrule_evenodd;
230 gfxpoly_t*poly = gfxpoly_from_file(filename, 0.01);
234 intbbox_t bbox = intbbox_from_polygon(poly, zoom);
236 if(!gfxpoly_check(poly)) {
237 printf("bad polygon\n");
241 gfxpoly_t*poly2 = gfxpoly_process(poly, rule);
242 unsigned char*bitmap1 = render_polygon(poly, &bbox, zoom, rule);
243 unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd);
244 if(!bitmap_ok(&bbox, bitmap1) || !bitmap_ok(&bbox, bitmap2)) {
245 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
246 assert(!"error in bitmaps");
248 if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
249 save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
250 assert(!"bitmaps don't match");
252 gfxpoly_destroy(poly2);