/* factor that determines into how many line fragments a spline is converted */
#define SUBFRACTION (2.4)
-static edge_t*edge_new(int x1, int y1, int x2, int y2)
-{
- edge_t*s = rfx_calloc(sizeof(edge_t));
- s->a.x = x1;
- s->a.y = y1;
- s->b.x = x2;
- s->b.y = y2;
- return s;
-}
-
static inline int32_t convert_coord(double x, double z)
{
/* we clamp to 31 bit instead of 32 bit because we use
}
}
-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;
-}
-
typedef struct _compactpoly {
- gfxcompactpoly_t*poly;
+ gfxpoly_t*poly;
point_t last;
int strokes_size;
point_t*points;
#endif
data->poly->num_strokes++;
}
-static void compactmoveto(polywriter_t*w, int x, int y)
+static void compactmoveto(polywriter_t*w, int32_t x, int32_t y)
{
compactpoly_t*data = (compactpoly_t*)w->internal;
point_t p;
}
data->last = p;
}
-static void compactlineto(polywriter_t*w, int x, int y)
+static void compactlineto(polywriter_t*w, int32_t x, int32_t y)
{
compactpoly_t*data = (compactpoly_t*)w->internal;
point_t p;
data->poly->strokes = (gfxpolystroke_t*)rfx_realloc(data->poly->strokes, sizeof(gfxpolystroke_t)*data->poly->num_strokes);
//qsort(data->poly->strokes, data->poly->num_strokes, sizeof(gfxpolystroke_t), compare_stroke);
free(data->points);
- gfxcompactpoly_t*poly = data->poly;
+ gfxpoly_t*poly = data->poly;
free(w->internal);w->internal = 0;
return (void*)poly;
}
-void gfxcompactpolywriter_init(polywriter_t*w)
+void gfxpolywriter_init(polywriter_t*w)
{
w->moveto = compactmoveto;
w->lineto = compactlineto;
w->setgridsize = compactsetgridsize;
w->finish = compactfinish;
compactpoly_t*data = w->internal = rfx_calloc(sizeof(compactpoly_t));
- data->poly = rfx_calloc(sizeof(gfxcompactpoly_t));
+ data->poly = rfx_calloc(sizeof(gfxpoly_t));
data->poly->gridsize = 1.0;
data->last.x = data->last.y = 0;
data->strokes_size = 16;
gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize)
{
- polywriter_t w;
- gfxpolywriter_init(&w);
- w.setgridsize(&w, gridsize);
- convert_gfxline(line, &w, gridsize);
- return w.finish(&w);
-}
-gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize)
-{
- polywriter_t w;
- gfxpolywriter_init(&w);
- w.setgridsize(&w, gridsize);
- convert_file(filename, &w, gridsize);
- return w.finish(&w);
-}
-gfxcompactpoly_t* gfxcompactpoly_from_gfxline(gfxline_t*line, double gridsize)
-{
polywriter_t writer;
- gfxcompactpolywriter_init(&writer);
+ gfxpolywriter_init(&writer);
writer.setgridsize(&writer, gridsize);
convert_gfxline(line, &writer, gridsize);
- return (gfxcompactpoly_t*)writer.finish(&writer);
+ return (gfxpoly_t*)writer.finish(&writer);
}
-gfxcompactpoly_t* gfxcompactpoly_from_file(const char*filename, double gridsize)
+gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize)
{
polywriter_t writer;
- gfxcompactpolywriter_init(&writer);
+ gfxpolywriter_init(&writer);
writer.setgridsize(&writer, gridsize);
convert_file(filename, &writer, gridsize);
- return (gfxcompactpoly_t*)writer.finish(&writer);
-}
-gfxpoly_t*gfxpoly_from_gfxcompactpoly(gfxcompactpoly_t*poly)
-{
- int s,t;
- int pass;
- gfxpoly_t*poly2 = gfxpoly_new(poly->gridsize);
- for(t=0;t<poly->num_strokes;t++) {
- gfxpolystroke_t*stroke = &poly->strokes[t];
- for(s=0;s<stroke->num_points-1;s++) {
- point_t a = stroke->points[s];
- point_t b = stroke->points[s+1];
- edge_t*e = 0;
- if(stroke->dir == DIR_UP) {
- e = edge_new(a.x,a.y,b.x,b.y);
- } else {
- e = edge_new(b.x,b.y,a.x,a.y);
- }
- e->style = stroke->fs;
- e->next = poly2->edges;
- poly2->edges = e;
- }
- }
- return poly2;
+ return (gfxpoly_t*)writer.finish(&writer);
}
-void gfxcompactpoly_destroy(gfxcompactpoly_t*poly)
+void gfxpoly_destroy(gfxpoly_t*poly)
{
int t;
for(t=0;t<poly->num_strokes;t++) {
#include "../gfxdevice.h"
#include "poly.h"
-gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize);
-gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize);
-gfxpoly_t* gfxpoly_from_gfxcompactpoly(gfxcompactpoly_t*poly);
-
typedef struct _polywriter
{
- void(*moveto)(struct _polywriter*, int x, int y);
- void(*lineto)(struct _polywriter*, int x, int y);
+ void(*moveto)(struct _polywriter*, int32_t x, int32_t y);
+ void(*lineto)(struct _polywriter*, int32_t x, int32_t y);
void(*setgridsize)(struct _polywriter*, double g);
void*(*finish)(struct _polywriter*);
void*internal;
} polywriter_t;
void gfxpolywriter_init(polywriter_t*w);
-void gfxcompactpolywriter_init(polywriter_t*w);
-
-gfxcompactpoly_t* gfxcompactpoly_from_gfxline(gfxline_t*line, double gridsize);
-gfxcompactpoly_t* gfxcompactpoly_from_file(const char*filename, double gridsize);
-
-void gfxcompactpoly_destroy(gfxcompactpoly_t*poly);
+gfxpoly_t* gfxpoly_from_gfxline(gfxline_t*line, double gridsize);
+gfxpoly_t* gfxpoly_from_file(const char*filename, double gridsize);
+void gfxpoly_destroy(gfxpoly_t*poly);
#endif //__poly_convert_h__
#include "wind.h"
#include "convert.h"
-static gfxcompactpoly_t*current_polygon = 0;
+static gfxpoly_t*current_polygon = 0;
void gfxpoly_fail(char*expr, char*file, int line, const char*function)
{
if(!current_polygon) {
fprintf(stderr, "assert(%s) failed in %s in line %d: %s\n", expr, file, line, function);
fprintf(stderr, "I'm saving a debug file \"%s\" to the current directory.\n", filename);
- gfxcompactpoly_save(current_polygon, filename);
+ gfxpoly_save(current_polygon, filename);
exit(1);
}
//return d;
}
-gfxpoly_t* gfxpoly_new(double gridsize)
-{
- gfxpoly_t*p = (gfxpoly_t*)rfx_calloc(sizeof(gfxpoly_t));
- p->gridsize = gridsize;
- return p;
-}
-void gfxpoly_destroy(gfxpoly_t*poly)
-{
- edge_t* s = poly->edges;
- while(s) {
- edge_t*next = s->next;
- free(s);
- s = next;
- }
- free(poly);
-}
int gfxpoly_size(gfxpoly_t*poly)
{
- edge_t*e = poly->edges;
- int count = 0;
- while(e) {
- count++;
- e = e->next;
- }
- return count;
-}
-int gfxcompactpoly_size(gfxcompactpoly_t*poly)
-{
int s,t;
int edges = 0;
for(t=0;t<poly->num_strokes;t++) {
char gfxpoly_check(gfxpoly_t*poly)
{
- edge_t* s = poly->edges;
- dict_t*d = dict_new2(&point_type);
- while(s) {
- if(!dict_contains(d, &s->a)) {
- dict_put(d, &s->a, (void*)(ptroff_t)1);
- } else {
- int count = (ptroff_t)dict_lookup(d, &s->a);
- dict_del(d, &s->a);
- count++;
- dict_put(d, &s->a, (void*)(ptroff_t)count);
- }
- if(!dict_contains(d, &s->b)) {
- dict_put(d, &s->b, (void*)(ptroff_t)1);
- } else {
- int count = (ptroff_t)dict_lookup(d, &s->b);
- dict_del(d, &s->b);
- count++;
- dict_put(d, &s->b, (void*)(ptroff_t)count);
- }
- s = s->next;
- }
- DICT_ITERATE_ITEMS(d, point_t*, p, void*, c) {
- int count = (ptroff_t)c;
- if(count&1) {
- fprintf(stderr, "Point (%f,%f) occurs %d times\n", p->x*poly->gridsize, p->y*poly->gridsize, count);
- dict_destroy(d);
- return 0;
- }
- }
- dict_destroy(d);
- return 1;
-}
-
-char gfxcompactpoly_check(gfxcompactpoly_t*poly)
-{
dict_t*d = dict_new2(&point_type);
int s,t;
for(t=0;t<poly->num_strokes;t++) {
void gfxpoly_dump(gfxpoly_t*poly)
{
- edge_t* s = poly->edges;
- double g = poly->gridsize;
- fprintf(stderr, "polyon %08x (gridsize: %f)\n", poly, poly->gridsize);
- while(s) {
- fprintf(stderr, "(%f,%f) -> (%f,%f)\n", s->a.x*g, s->a.y*g, s->b.x*g, s->b.y*g);
- s = s->next;
- }
-}
-
-void gfxcompactpoly_dump(gfxcompactpoly_t*poly)
-{
int s,t;
double g = poly->gridsize;
fprintf(stderr, "polyon %08x (gridsize: %f)\n", poly, poly->gridsize);
}
}
-void gfxcompactpoly_save(gfxcompactpoly_t*poly, const char*filename)
+void gfxpoly_save(gfxpoly_t*poly, const char*filename)
{
FILE*fi = fopen(filename, "wb");
fprintf(fi, "%% gridsize %f\n", poly->gridsize);
}
}
-static void gfxpoly_enqueue(gfxcompactpoly_t*p, heap_t*queue, int polygon_nr)
+static void gfxpoly_enqueue(gfxpoly_t*p, heap_t*queue, int polygon_nr)
{
int t;
for(t=0;t<p->num_strokes;t++) {
return box;
}
-
static void insert_point_into_segment(status_t*status, segment_t*s, point_t p)
{
assert(s->pos.x != p.x || s->pos.y != p.y);
}
#endif
-static void add_horizontals(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context)
+static void add_horizontals(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context)
{
/*
|..| |...........| | |
heap_destroy(queue);
}
-gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context)
+gfxpoly_t* gfxpoly_process(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context)
{
current_polygon = poly;
heap_t* queue = heap_new(sizeof(event_t), compare_events);
status.windrule = windrule;
status.context = context;
status.actlist = actlist_new();
- gfxcompactpolywriter_init(&status.writer);
+ gfxpolywriter_init(&status.writer);
status.writer.setgridsize(&status.writer, poly->gridsize);
#ifdef CHECKS
heap_destroy(queue);
xrow_destroy(status.xrow);
- gfxcompactpoly_t*p = (gfxcompactpoly_t*)status.writer.finish(&status.writer);
+ gfxpoly_t*p = (gfxpoly_t*)status.writer.finish(&status.writer);
add_horizontals(p, &windrule_evenodd, context); // output is always even/odd
- gfxpoly_t*pp = gfxpoly_from_gfxcompactpoly(p);
- gfxcompactpoly_destroy(p);
- return pp;
+ return p;
}
char is_filled;
} fillstyle_t;
-typedef struct _edge {
- point_t a;
- point_t b;
- fillstyle_t*style;
-#ifdef DEBUG
- int tmp;
-#endif
- struct _edge *next;
-} edge_t;
-
typedef struct _windstate
{
char is_filled;
int num_points;
point_t*points;
fillstyle_t*fs;
+ struct _gfxpolystroke*next;
} gfxpolystroke_t;
-typedef struct _gfxcompactpoly {
+typedef struct _gfxpoly {
double gridsize;
int num_strokes;
gfxpolystroke_t*strokes;
-} gfxcompactpoly_t;
+} gfxpoly_t;
typedef struct _segment {
point_t a;
#define XDIFF(s1,s2,ypos) (((s1)->k + (double)(s1)->delta.x*ypos)*(s2)->delta.y - \
((s2)->k + (double)(s2)->delta.x*ypos)*(s1)->delta.y)
-typedef struct _gfxpoly {
- double gridsize;
- edge_t*edges;
-} gfxpoly_t;
-
void gfxpoly_fail(char*expr, char*file, int line, const char*function);
-gfxpoly_t* gfxpoly_new(double gridsize);
-char gfxcompactpoly_check(gfxcompactpoly_t*poly);
-int gfxcompactpoly_size(gfxcompactpoly_t*poly);
-void gfxcompactpoly_dump(gfxcompactpoly_t*poly);
-void gfxcompactpoly_save(gfxcompactpoly_t*poly, const char*filename);
-gfxpoly_t* gfxpoly_process(gfxcompactpoly_t*poly, windrule_t*windrule, windcontext_t*context);
+char gfxpoly_check(gfxpoly_t*poly);
+int gfxpoly_size(gfxpoly_t*poly);
+void gfxpoly_dump(gfxpoly_t*poly);
+void gfxpoly_save(gfxpoly_t*poly, const char*filename);
+gfxpoly_t* gfxpoly_process(gfxpoly_t*poly, windrule_t*windrule, windcontext_t*context);
#ifndef CHECKS
#ifdef assert
double x;
segment_dir_t dir;
fillstyle_t*fs;
- edge_t*e; //only for debugging
int polygon_nr;
} renderpoint_t;
renderline_t*lines;
} renderbuf_t;
-static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr, edge_t*e)
+static inline void add_pixel(renderbuf_t*buf, double x, int y, segment_dir_t dir, fillstyle_t*fs, int polygon_nr)
{
renderpoint_t p;
p.x = x;
p.dir = dir;
p.fs = fs;
- p.e = e;
p.polygon_nr = polygon_nr;
if(y >= buf->bbox.ymax || y < buf->bbox.ymin)
l->num++;
}
#define CUT 0.5
-static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr, edge_t*e)
+static void add_line(renderbuf_t*buf, double x1, double y1, double x2, double y2, fillstyle_t*fs, int polygon_nr)
{
x1 *= buf->zoom;
y1 *= buf->zoom;
while(posy<=endy) {
double xx = startx + posx;
- add_pixel(buf, xx, posy, dir, fs, polygon_nr, e);
+ add_pixel(buf, xx, posy, dir, fs, polygon_nr);
posx+=stepx;
posy++;
}
buf->lines[y].num = 0;
}
- edge_t*e;
int polygon_nr = 0;
- for(e=polygon->edges;e;e=e->next) {
- add_line(buf, e->a.x, e->a.y, e->b.x, e->b.y, e->style, polygon_nr, e);
+ int s,t;
+ for(s=0;s<polygon->num_strokes;s++) {
+ gfxpolystroke_t*stroke = &polygon->strokes[s];
+ for(t=0;t<stroke->num_points-1;t++) {
+ point_t a = stroke->points[t];
+ point_t b = stroke->points[t+1];
+ add_line(buf, a.x, a.y, b.x, b.y, stroke->fs, polygon_nr);
+ }
}
for(y=0;y<buf->height;y++) {
intbbox_t intbbox_from_polygon(gfxpoly_t*polygon, double zoom)
{
- int t;
intbbox_t b = {0,0,0,0};
- edge_t*e = polygon->edges;
double g = zoom*polygon->gridsize;
- if(e) {
- b.xmin = e->a.x*g;
- b.ymin = e->a.y*g;
- b.xmax = e->a.x*g;
- b.ymax = e->a.y*g;
+ if(polygon->num_strokes && polygon->strokes[0].num_points) {
+ b.xmin = polygon->strokes[0].points[0].x*g;
+ b.ymin = polygon->strokes[0].points[0].y*g;
+ b.xmax = polygon->strokes[0].points[0].x*g;
+ b.ymax = polygon->strokes[0].points[0].y*g;
}
- for(e=polygon->edges;e;e=e->next) {
- double x_min = min(e->a.x,e->b.x)*g;
- double y_min = min(e->a.y,e->b.y)*g;
- double x_max = max(e->a.x,e->b.x)*g;
- double y_max = max(e->a.y,e->b.y)*g;
- int x1 = floor(x_min);
- int y1 = floor(y_min);
- int x2 = ceil(x_max);
- int y2 = ceil(y_max);
- if(x1 < b.xmin) b.xmin = x1;
- if(y1 < b.ymin) b.ymin = y1;
- if(x2 > b.xmax) b.xmax = x2;
- if(y2 > b.ymax) b.ymax = y2;
+ int s,t;
+ for(s=0;s<polygon->num_strokes;s++) {
+ gfxpolystroke_t*stroke = &polygon->strokes[s];
+ for(t=0;t<stroke->num_points;t++) {
+ point_t p = stroke->points[t];
+ int x1 = floor(p.x);
+ int y1 = floor(p.y);
+ int x2 = ceil(p.x);
+ int y2 = ceil(p.y);
+ if(x1 < b.xmin) b.xmin = x1;
+ if(y1 < b.ymin) b.ymin = y1;
+ if(x2 > b.xmax) b.xmax = x2;
+ if(y2 > b.ymax) b.ymax = y2;
+ }
}
if(b.xmax > (int)(MAX_WIDTH*zoom))
{
//gfxline_t* b = mkchessboard();
//gfxline_t* b = mkrandomshape(100,7);
- gfxline_t* b = make_circles(30);
+ gfxline_t* b = make_circles(100);
gfxmatrix_t m;
memset(&m, 0, sizeof(gfxmatrix_t));
m.ty = 400*1.41/2;
gfxline_t*l = gfxline_clone(b);
gfxline_transform(l, &m);
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(b, 0.05);
+ gfxpoly_t*poly = gfxpoly_from_gfxline(b, 0.05);
gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
- gfxcompactpoly_destroy(poly);
+ gfxpoly_destroy(poly);
gfxpoly_destroy(poly2);
gfxline_free(l);
}
gfxline_dump(b, stderr, "");
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(b, 0.05);
+ gfxpoly_t*poly = gfxpoly_from_gfxline(b, 0.05);
gfxline_free(box1);
gfxline_free(box2);
gfxline_free(box3);
gfxline_free(star);
- gfxcompactpoly_dump(poly);
+ gfxpoly_dump(poly);
gfxpoly_t*poly2 = gfxpoly_process(poly, &windrule_evenodd, &onepolygon);
- gfxcompactpoly_destroy(poly);
+ gfxpoly_destroy(poly);
gfxpoly_destroy(poly2);
}
-static void test_conversion(gfxline_t*line, double gridsize)
-{
- double zoom=1.0;
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, gridsize);
- gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, gridsize);
- gfxpoly_t*poly2 = gfxpoly_from_gfxcompactpoly(poly);
- assert(gfxpoly_check(poly1));
- assert(gfxpoly_check(poly2));
- assert(gfxcompactpoly_check(poly));
- intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
- unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, &windrule_evenodd, &onepolygon);
- assert(bitmap_ok(&bbox, bitmap1));
- unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
- assert(bitmap_ok(&bbox, bitmap2));
- if(!compare_bitmaps(&bbox, bitmap1, bitmap2)) {
- save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
- assert(!"bitmaps don't match");
- }
-}
-
int test_square(int width, int height, int num, double gridsize, char bitmaptest)
{
int t;
line[num-1].y = line[0].y;
line[num-1].next = 0;
- test_conversion(line, gridsize);
-
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, gridsize);
+ gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, gridsize);
gfxline_free(line);
- gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
windrule_t*rule = &windrule_circular;
- gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
if(bitmaptest) {
intbbox_t bbox = intbbox_new(0, 0, width, height);
unsigned char*bitmap1 = render_polygon(poly1, &bbox, 1.0, rule, &onepolygon);
}
gfxpoly_destroy(poly1);
gfxpoly_destroy(poly2);
- gfxcompactpoly_destroy(poly);
}
int test2(int argn, char*argv[])
gfxline_t*l = gfxline_clone(line);
gfxline_transform(l, &m);
- test_conversion(l, 0.05);
-
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(l, 0.05);
- gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+ gfxpoly_t*poly1 = gfxpoly_from_gfxline(l, 0.05);
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
tag = swf_InsertTag(tag, ST_DEFINESHAPE);
SHAPE* s;
#define FILL
#ifdef FILL
swf_ShapeSetAll(tag,s,0,0,0,fs,0);
- edge_t*e = poly2->edges;
- while(e) {
+
+ int i,j;
+ for(i=0;i<poly2->num_strokes;i++) {
+ gfxpolystroke_t*stroke = &poly2->strokes[i];
+ for(j=0;j<stroke->num_points-1;j++) {
+ point_t a = stroke->points[j];
+ point_t b = stroke->points[j+1];
#define ROTATE
#ifdef ROTATE
- swf_ShapeSetMove(tag, s, e->a.y, e->a.x);
- swf_ShapeSetLine(tag, s, e->b.y - e->a.y, e->b.x - e->a.x);
+ swf_ShapeSetMove(tag, s, a.y, a.x);
+ swf_ShapeSetLine(tag, s, b.y - a.y, b.x - a.x);
#else
- swf_ShapeSetMove(tag, s, e->a.x, e->a.y);
- swf_ShapeSetLine(tag, s, e->b.x - e->a.x, e->b.y - e->a.y);
+ swf_ShapeSetMove(tag, s, a.x, a.y);
+ swf_ShapeSetLine(tag, s, b.x - a.x, b.y - a.y);
#endif
- e = e->next;
- }
+ }
+ }
#else
swf_ShapeSetAll(tag,s,0,0,ls,0,0);
edge_t*e = poly2->edges;
swf_ShapeSetEnd(tag);
swf_ShapeFree(s);
- gfxcompactpoly_destroy(poly);
+ gfxpoly_destroy(poly1);
gfxpoly_destroy(poly2);
gfxline_free(l);
void rotate90(gfxpoly_t*poly)
{
- edge_t*e = poly->edges;
- while(e) {
- point_t a = e->a;
- point_t b = e->b;
- e->a.x = a.y;
- e->a.y = a.x;
- e->b.x = b.y;
- e->b.y = b.x;
- e = e->next;
+ int i,j;
+ for(i=0;i<poly->num_strokes;i++) {
+ gfxpolystroke_t*stroke = &poly->strokes[i];
+ for(j=0;j<stroke->num_points;j++) {
+ point_t a = stroke->points[j];
+ stroke->points[j].x = a.y;
+ stroke->points[j].y = a.x;
+ }
}
}
filename = argv[1];
windrule_t*rule = &windrule_evenodd;
- gfxcompactpoly_t*poly = gfxcompactpoly_from_file(filename, 1.0);//0.01);
+ gfxpoly_t*poly1 = gfxpoly_from_file(filename, 1.0);//0.01);
if(argn!=2)
free(filename);
double zoom = 1.0;
- if(!gfxcompactpoly_check(poly)) {
+ if(!gfxpoly_check(poly1)) {
printf("bad polygon\n");
continue;
}
- gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
- gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
int pass;
for(pass=0;pass<2;pass++) {
gfxpoly_destroy(poly1);
gfxpoly_destroy(poly2);
- gfxcompactpoly_destroy(poly);
if(argn==2)
break;
}
void extract_polygons_fill(gfxdevice_t*dev, gfxline_t*line, gfxcolor_t*color)
{
- //gfxcompactpoly_t*c = gfxcompactpoly_from_gfxline(line, 0.05);
- //gfxcompactpoly_free(c);
+ //gfxpoly_t*c = gfxpoly_from_gfxline(line, 0.05);
+ //gfxpoly_free(c);
- gfxcompactpoly_t*poly = gfxcompactpoly_from_gfxline(line, 0.05);
+ gfxpoly_t*poly1 = gfxpoly_from_gfxline(line, 0.05);
//gfxline_dump(line, stderr, "");
- //gfxcompactpoly_dump(poly);
+ //gfxpoly_dump(poly);
- if(gfxcompactpoly_size(poly)>100000) {
- fprintf(stderr, "%d segments (skipping)\n", gfxcompactpoly_size(poly));
+ if(gfxpoly_size(poly1)>100000) {
+ fprintf(stderr, "%d segments (skipping)\n", gfxpoly_size(poly1));
return;
} else {
//fprintf(stderr, "%d segments\n", gfxpoly_size(poly));
}
- if(!gfxcompactpoly_check(poly)) {
- gfxcompactpoly_destroy(poly);
+ if(!gfxpoly_check(poly1)) {
+ gfxpoly_destroy(poly1);
fprintf(stderr, "bad polygon\n");
return;
}
windrule_t*rule = &windrule_evenodd;
- gfxpoly_t*poly1 = gfxpoly_from_gfxcompactpoly(poly);
-
double zoom = 1.0;
intbbox_t bbox = intbbox_from_polygon(poly1, zoom);
unsigned char*bitmap1 = render_polygon(poly1, &bbox, zoom, rule, &onepolygon);
fprintf(stderr, "bad polygon or error in renderer\n");
return;
}
- gfxpoly_t*poly2 = gfxpoly_process(poly, rule, &onepolygon);
+ gfxpoly_t*poly2 = gfxpoly_process(poly1, rule, &onepolygon);
unsigned char*bitmap2 = render_polygon(poly2, &bbox, zoom, &windrule_evenodd, &onepolygon);
if(!bitmap_ok(&bbox, bitmap2)) {
save_two_bitmaps(&bbox, bitmap1, bitmap2, "error.png");
gfxpoly_destroy(poly1);
gfxpoly_destroy(poly2);
- gfxcompactpoly_destroy(poly);
}
int extract_polygons_setparameter(gfxdevice_t*dev, const char*key, const char*value) {
return 0;
int main(int argn, char*argv[])
{
- test_speed(argn, argv);
+ test4(argn, argv);
}