Index: work/polydev/Makefile =================================================================== --- work/polydev/Makefile (nonexistent) +++ work/polydev/Makefile (revision 8172) @@ -0,0 +1,15 @@ +TRUNK=../../trunk +S=$(TRUNK)/src +CFLAGS = -Wall -g -ansi -pedantic -I$(TRUNK) -I$S -I$(TRUNK)/src_3rd -I$(TRUNK)/src_3rd/liblihata -Dinline= +PCB_RND_OBJS = \ + $S/polygon1.o \ + $S/pcb-printf.o \ + $S/unit.o \ + $S/rtree.o \ + $S/heap.o \ + $S/compat_misc.o \ + $(TRUNK)/src_3rd/liblihata/genht/hash.o \ + $(TRUNK)/src_3rd/genvector/gds_char.o +LDLIBS=-lm + +test: test.o $(PCB_RND_OBJS) Index: work/polydev/test.c =================================================================== --- work/polydev/test.c (nonexistent) +++ work/polydev/test.c (revision 8172) @@ -0,0 +1,120 @@ +#include +#include +#include +#include "unit.h" +#include "pcb_bool.h" +#include "rtree.h" +#include "polyarea.h" +#include "polygon.h" + +pcb_polyarea_t *pcb_poly_from_contour(pcb_pline_t * contour) +{ + pcb_polyarea_t *p; + pcb_poly_contour_pre(contour, pcb_true); + if (!(p = pcb_polyarea_create())) + return NULL; + pcb_polyarea_contour_include(p, contour); + return p; +} + +static void draw_(pcb_pline_t *c, int outer) +{ + 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; + +#define update_minmax(min, 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); + printf("viewport %ld %ld - %ld %ld\n", (long)minx, (long)miny, (long)maxx, (long)maxy); + 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]); + } + while ((v = v->next) != pl); + +#undef update_minmax +} + +static void draw(pcb_polyarea_t *p) +{ + pcb_pline_t *c; + + printf("!!!animator start\n"); + + draw_(p->contours, 1); + + for (c = p->contours->next; c != NULL; c = c->next) + draw_(c, 0); + printf("flush\n"); + printf("!!!animator end\n"); +} + +pcb_polyarea_t *ply_parse(const char *vect) +{ + pcb_pline_t *contour = NULL; + long int x, y; + int len; + pcb_vector_t v; + + if (sscanf(vect, "%ld %ld%n", &x, &y, &len) != 2) + return NULL; + vect += len; + v[0] = x; v[1] = y; + if ((contour = pcb_poly_contour_new(v)) == NULL) + return NULL; + + while(sscanf(vect, "%ld %ld%n", &x, &y, &len) == 2) { + vect += len; + v[0] = x; v[1] = y; + pcb_poly_vertex_include(contour->head.prev, pcb_poly_node_create(v)); + } + + return pcb_poly_from_contour(contour); +} + +int main() +{ + char line[8192], *cmd, *arg; + pcb_polyarea_t *pa; + + + while(fgets(line, sizeof(line), stdin) != NULL) { + cmd = line; + while(isspace(*cmd)) cmd++; + if ((*cmd == '#') || (*cmd == '\0')) + continue; + arg = strpbrk(cmd, " \t\r\n"); + if (arg != NULL) { + *arg = '\0'; + arg++; + while(isspace(*arg)) arg++; + } + if (strcmp(cmd, "polygon") == 0) { + pa = ply_parse(arg); + if (pa == NULL) + fprintf(stderr, "poly parse error\n"); + } + else if (strcmp(cmd, "draw") == 0) + draw(pa); + else if (strcmp(cmd, "echo") == 0) + printf(arg); + else + fprintf(stderr, "syntax error\n"); + } + return 0; +}