Index: work/polydev/test.c =================================================================== --- work/polydev/test.c (revision 8184) +++ work/polydev/test.c (revision 8185) @@ -24,36 +24,22 @@ return p; } -static void draw_(pcb_pline_t *c, int outer) +static void update_bbox(pcb_pline_t *c, pcb_coord_t *minx, pcb_coord_t *miny, pcb_coord_t *maxx, pcb_coord_t *maxy) { pcb_vnode_t *v, *n; pcb_vnode_t *pl = &c->head; - pcb_coord_t minx = COORD_MAX, miny = COORD_MAX, maxx = -COORD_MAX, maxy = -COORD_MAX, w, h; #define update_minmax(min, max, val) \ - if (val < min) min = val; \ - if (val > max) max = val; + if (val < (min)) (min) = val; \ + if (val > (max)) (max) = val; - if (outer) { - v = pl; - do { - n = v->next; - update_minmax(minx, maxx, v->point[0]); - update_minmax(miny, maxy, v->point[1]); - update_minmax(minx, maxx, n->point[0]); - update_minmax(miny, maxy, n->point[1]); - } - while ((v = v->next) != pl); - w = maxx - minx; - h = maxy - miny; - printf("ident\nscale 1 -1\n"); - printf("viewport %f %f - %f %f\n", (minx - w/20.0), (miny - h/20.0), (maxx + w/20.0), (maxy + h/20.0)); - printf("frame\n"); - } v = pl; do { n = v->next; - printf("line %ld %ld %ld %ld\n", (long)v->point[0], (long)v->point[1], (long)n->point[0], (long)n->point[1]); + update_minmax(*minx, *maxx, v->point[0]); + update_minmax(*miny, *maxy, v->point[1]); + update_minmax(*minx, *maxx, n->point[0]); + update_minmax(*miny, *maxy, n->point[1]); } while ((v = v->next) != pl); @@ -60,19 +46,59 @@ #undef update_minmax } -static void draw(pcb_polyarea_t *p) +static void draw_(pcb_pline_t *c) { + pcb_vnode_t *v, *n; + pcb_vnode_t *pl = &c->head; + + v = pl; + do { + n = v->next; + printf("line %ld %ld %ld %ld\n", (long)v->point[0], (long)v->point[1], (long)n->point[0], (long)n->point[1]); + } + while ((v = v->next) != pl); +} + +static void draw(const char *arg) +{ pcb_pline_t *c; + pcb_coord_t minx = COORD_MAX, miny = COORD_MAX, maxx = -COORD_MAX, maxy = -COORD_MAX, w, h; + int drw['Z' - 'A']; + int cnt = 0, n; + while(*arg != '\0') { + int a; + while(isspace(*arg)) arg++; + if (*arg == '\0') + break; + a = toupper(*arg); + if ((a < 'A') || (a > 'Z')) { + fprintf(stderr, "Error: invalid index in draw: '%c' (%d)\n", a, a); + return; + } + drw[cnt] = a - 'A'; + update_bbox(pa[drw[cnt]]->contours, &minx, &miny, &maxx, &maxy); + cnt++; + arg++; + } + printf("!!!animator start\n"); - printf("dash 0xffff\n"); - draw_(p->contours, 1); + w = maxx - minx; + h = maxy - miny; + printf("ident\nscale 1 -1\n"); + printf("viewport %f %f - %f %f\n", (minx - w/20.0), (miny - h/20.0), (maxx + w/20.0), (maxy + h/20.0)); + printf("frame\n"); - for (c = p->contours->next; c != NULL; c = c->next) { - printf("!hole:\n"); - printf("dash 0x3333\n"); - draw_(c, 0); + for(n = 0; n < cnt; n++) { + pcb_polyarea_t *p = pa[drw[n]]; + printf("dash 0xffff\n"); + draw_(p->contours); + + for (c = p->contours->next; c != NULL; c = c->next) { + printf("dash 0x3333\n"); + draw_(c); + } } printf("flush\n"); printf("!!!animator end\n"); @@ -211,7 +237,6 @@ { char line[8192], *cmd, *arg; - while(fgets(line, sizeof(line), stdin) != NULL) { cmd = line; while(isspace(*cmd)) cmd++; @@ -229,10 +254,8 @@ if (pa[idx] == NULL) fprintf(stderr, "poly parse error\n"); } - else if (strcmp(cmd, "draw") == 0) { - get_idx(); - draw(pa[idx]); - } + else if (strcmp(cmd, "draw") == 0) + draw(arg); else if (strcmp(cmd, "echo") == 0) printf(arg); else if (strcmp(cmd, "check") == 0) {