-typedef struct _stdpoly {
- gfxpoly_t*poly;
- double lastx,lasty;
-} stdpoly_t;
-
-static void stdmoveto(polywriter_t*w, int x, int y)
-{
- stdpoly_t*d = (stdpoly_t*)w->internal;
- d->lastx = x;d->lasty = y;
-}
-static void stdlineto(polywriter_t*w, int x, int y)
-{
- stdpoly_t*d = (stdpoly_t*)w->internal;
- int x1 = d->lastx;
- int y1 = d->lasty;
- int x2 = x;
- int y2 = y;
- if(x1!=x2 || y1!=y2) {
- edge_t*s = edge_new(x1, y1, x2, y2);
- s->next = d->poly->edges;
- d->poly->edges = s;
- }
- d->lastx = x;d->lasty = y;
-}
-static void stdsetgridsize(polywriter_t*w, double gridsize)
-{
- stdpoly_t*d = (stdpoly_t*)w->internal;
- d->poly->gridsize = gridsize;
-}
-static void* stdfinish(polywriter_t*w)
-{
- stdpoly_t*d = (stdpoly_t*)w->internal;
- gfxpoly_t*poly = d->poly;
- free(w->internal);w->internal = 0;
- return poly;
-}
-void gfxpolywriter_init(polywriter_t*w)
-{
- w->moveto = stdmoveto;
- w->lineto = stdlineto;
- w->setgridsize = stdsetgridsize;
- w->finish = stdfinish;
- stdpoly_t*data = w->internal = malloc(sizeof(stdpoly_t));
- data->poly = gfxpoly_new(1.0);
- data->lastx = 0;
- data->lasty = 0;
-}
-