first version of new polygon intersector
[swftools.git] / lib / gfxpoly / test.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <memory.h>
4 #include <math.h>
5 #include "../gfxtools.h"
6 #include "poly.h"
7 #include "convert.h"
8
9 gfxline_t*mkstar(int x1, int y1, int x2, int y2)
10 {
11     gfxline_t*l=0,*line = 0;
12     int x;
13     for(x=x1;x<=x2;x+=50) {
14         l = malloc(sizeof(gfxline_t));
15         l->type = gfx_moveTo;
16         l->x = x;l->y = y1;
17         line = gfxline_append(line, l);
18
19         l = malloc(sizeof(gfxline_t));
20         l->type = gfx_lineTo;
21         l->x = x2-x;l->y = y2;
22         line = gfxline_append(line, l);
23     }
24     return line;
25 }
26
27 int test1()
28 {
29     gfxline_t*box1 = gfxline_makerectangle(50,50,150,150);
30
31     // put box2 and box3 on top of each other *snicker*
32     gfxline_t*box2 = gfxline_makerectangle(100,100,200,200);
33     gfxline_t*box3 = gfxline_makerectangle(100,100,200,200);
34     gfxline_t*star = mkstar(50,50, 150,150);
35     gfxline_t*b = 0;
36     b = gfxline_append(b, box1);
37     b = gfxline_append(b, box2);
38     b = gfxline_append(b, box3);
39     b = gfxline_append(b, star);
40
41     gfxmatrix_t matrix;
42     memset(&matrix, 0, sizeof(gfxmatrix_t));
43     double ua=0.1;
44     matrix.m00=cos(ua);matrix.m10=sin(ua);
45     matrix.m01=-sin(ua);matrix.m11=cos(ua);
46
47     gfxline_transform(b, &matrix);
48     gfxpoly_t*poly = gfxpoly_fillToPoly(b);
49     gfxline_free(box1);
50     gfxline_free(box2);
51     gfxline_free(box3);
52
53     gfxpoly_dump(poly);
54     gfxpoly_process(poly);
55 }
56
57 int test2()
58 {
59 #define N 1000
60     int t;
61     gfxline_t* line = malloc(sizeof(gfxline_t)*N);
62     for(t=0;t<N;t++) {
63         line[t].type = t?gfx_lineTo:gfx_moveTo;
64         line[t].x = lrand48()%65536;
65         line[t].y = lrand48()%65536;
66         line[t].next = &line[t+1];
67     }
68     line[N-1].x = line[0].x;
69     line[N-1].y = line[0].y;
70     line[N-1].next = 0;
71     
72     gfxpoly_t*poly = gfxpoly_fillToPoly(line);
73     gfxpoly_dump(poly);
74     gfxpoly_process(poly);
75     gfxline_free(line);
76 }
77
78 int main()
79 {
80     test2();
81 }