diff options
author | Matthias Kramm <kramm@quiss.org> | 2010-06-01 11:02:56 -0700 |
---|---|---|
committer | Matthias Kramm <kramm@quiss.org> | 2010-06-01 11:02:56 -0700 |
commit | 9b4a07900f07d05f0f39c511c189489114817aba (patch) | |
tree | 14dc66f7c206554b49c90bd0ae8aa4e22b8b5923 | |
parent | 879d0eec420fe0fd5ddcd56c8fe62b82a6744edd (diff) |
bugfixes, refactoring
-rw-r--r-- | lib/gfxpoly/convert.c | 18 | ||||
-rw-r--r-- | lib/gfxpoly/poly.c | 31 | ||||
-rw-r--r-- | lib/gfxpoly/test.c | 8 | ||||
-rw-r--r-- | lib/gfxpoly/wind.c | 3 | ||||
-rw-r--r-- | lib/gfxpoly/wind.h | 2 |
5 files changed, 41 insertions, 21 deletions
diff --git a/lib/gfxpoly/convert.c b/lib/gfxpoly/convert.c index 28c3b7ac..bb019422 100644 --- a/lib/gfxpoly/convert.c +++ b/lib/gfxpoly/convert.c @@ -167,19 +167,29 @@ static void compactmoveto(polywriter_t*w, int32_t x, int32_t y) } data->last = p; } + +static inline int direction(point_t p1, point_t p2) +{ + int diff = p1.y - p2.y; + if(diff) return diff; + return p1.x - p2.x; +} + static void compactlineto(polywriter_t*w, int32_t x, int32_t y) { compactpoly_t*data = (compactpoly_t*)w->internal; point_t p; p.x = x; p.y = y; - if(p.x == data->last.x && p.y == data->last.y) + + int diff = direction(p, data->last); + if(!diff) return; + segment_dir_t dir = diff<0?DIR_UP:DIR_DOWN; - if((p.y < data->last.y && data->dir != DIR_UP) || - (p.y > data->last.y && data->dir != DIR_DOWN) || data->new) { + if(dir!=data->dir || data->new) { finish_segment(data); - data->dir = p.y > data->last.y ? DIR_DOWN : DIR_UP; + data->dir = dir; data->points[0] = data->last; data->num_points = 1; } diff --git a/lib/gfxpoly/poly.c b/lib/gfxpoly/poly.c index 8711a00a..16b8ca73 100644 --- a/lib/gfxpoly/poly.c +++ b/lib/gfxpoly/poly.c @@ -239,8 +239,8 @@ char gfxpoly_check(gfxpoly_t*poly, char updown) DICT_ITERATE_ITEMS(d2, point_t*, p2, void*, c2) { int count = (ptroff_t)c2; if(count!=0) { - if(count>0) fprintf(stderr, "Error: Point (%d,%d) has %d more incoming than outgoing segments\n", p2->x, p2->y, count); - if(count<0) fprintf(stderr, "Error: Point (%d,%d) has %d more outgoing than incoming segments\n", p2->x, p2->y, -count); + if(count>0) fprintf(stderr, "Error: Point (%.2f,%.2f) has %d more incoming than outgoing segments\n", p2->x * poly->gridsize, p2->y * poly->gridsize, count); + if(count<0) fprintf(stderr, "Error: Point (%.2f,%.2f) has %d more outgoing than incoming segments\n", p2->x * poly->gridsize, p2->y * poly->gridsize, -count); dict_destroy(d2); return 0; } @@ -382,6 +382,8 @@ static void segment_dump(segment_t*s) static void segment_init(segment_t*s, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int polygon_nr, segment_dir_t dir) { + static int segment_count=0; + s->nr = segment_count++; s->dir = dir; if(y1!=y2) { assert(y1<y2); @@ -390,13 +392,16 @@ static void segment_init(segment_t*s, int32_t x1, int32_t y1, int32_t x2, int32_ "up/down" for horizontal segments is handled by "rotating" them 90° counterclockwise in screen coordinates (tilt your head to the right). In other words, the "normal" direction (what's positive dy for - vertical segments) is positive dx for horizontal segments. + vertical segments) is positive dx for horizontal segments ("down" is right). */ if(x1>x2) { s->dir = DIR_INVERT(s->dir); int32_t x = x1;x1=x2;x2=x; int32_t y = y1;y1=y2;y2=y; } + fprintf(stderr, "Scheduling horizontal segment [%d] (%.2f,%.2f) -> (%.2f,%.2f) %s\n", + segment_count, + x1 * 0.05, y1 * 0.05, x2 * 0.05, y2 * 0.05, s->dir==DIR_UP?"up":"down"); } s->a.x = x1; s->a.y = y1; @@ -411,8 +416,6 @@ static void segment_init(segment_t*s, int32_t x1, int32_t y1, int32_t x2, int32_ s->pos = s->a; s->polygon_nr = polygon_nr; - static int segment_count=0; - s->nr = segment_count++; #ifdef CHECKS /* notice: on some systems (with some compilers), for the line @@ -1091,8 +1094,9 @@ static void intersect_with_horizontal(status_t*status, segment_t*h) segment_t* left = actlist_find(status->actlist, h->a, h->a); segment_t* right = actlist_find(status->actlist, h->b, h->b); - /* not strictly necessary, also done by the event */ + /* h->a.x is not strictly necessary, as it's also done by the event */ xrow_add(status->xrow, h->a.x); + xrow_add(status->xrow, h->b.x); if(!right) { assert(!left); @@ -1189,9 +1193,10 @@ static void process_horizontals(status_t*status) segment_t* left = actlist_find(status->actlist, p1, p2); assert(!left || left->fs_out_ok); #ifdef DEBUG - fprintf(stderr, " fragment %.2f..%.2f\n", + fprintf(stderr, " fragment %.2f..%.2f edge=%08x\n", x * status->gridsize, - next_x * status->gridsize); + next_x * status->gridsize, + h->fs); if(left) { fprintf(stderr, " segment [%d] (%.2f,%.2f -> %.2f,%2f, at %.2f,%.2f) is to the left\n", SEGNR(left), @@ -1217,10 +1222,14 @@ static void process_horizontals(status_t*status) #ifdef DEBUG fprintf(stderr, " ...storing\n"); #endif - append_stroke(status, p1, p2, h->dir, fs); + append_stroke(status, p1, p2, DIR_INVERT(h->dir), fs); } else { #ifdef DEBUG - fprintf(stderr, " ...ignoring\n"); + fprintf(stderr, " ...ignoring (below: (wind_nr=%d, filled=%d), above: (wind_nr=%d, filled=%d) %s\n", + below.wind_nr, below.is_filled, + above.wind_nr, above.is_filled, + h->dir==DIR_UP?"up":"down" + ); #endif } x = next_x; @@ -1362,6 +1371,8 @@ gfxpoly_t* gfxpoly_process(gfxpoly_t*poly1, gfxpoly_t*poly2, windrule_t*windrule status_t status; memset(&status, 0, sizeof(status_t)); status.gridsize = poly1->gridsize; + + gfxpoly_dump(poly1); queue_init(&status.queue); gfxpoly_enqueue(poly1, &status.queue, 0, /*polygon nr*/0); diff --git a/lib/gfxpoly/test.c b/lib/gfxpoly/test.c index 46df1f5c..175f5313 100644 --- a/lib/gfxpoly/test.c +++ b/lib/gfxpoly/test.c @@ -183,8 +183,10 @@ int testbox(int argn, char*argv[]) int teststroke(int argn, char*argv[]) { - gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100); - assert(gfxpoly_check(gfxpoly_from_stroke(box1, 2.0, gfx_capRound, gfx_joinRound, 0, 0.05), 1)); + //gfxline_t*box1 = gfxline_makerectangle(-100,-100,100,100); + gfxline_t*box1 = gfxline_makerectangle(100,100,200,200); + gfxpoly_t*poly = gfxpoly_from_stroke(box1, 10.0, gfx_capRound, gfx_joinMiter, 1000, 0.05); + assert(gfxpoly_check(poly, 1)); } int test0(int argn, char*argv[]) @@ -666,6 +668,6 @@ void test5(int argn, char*argv[]) int main(int argn, char*argv[]) { - teststroke(argn, argv); + test4(argn, argv); } diff --git a/lib/gfxpoly/wind.c b/lib/gfxpoly/wind.c index e7cf95d0..30a21fd2 100644 --- a/lib/gfxpoly/wind.c +++ b/lib/gfxpoly/wind.c @@ -35,9 +35,6 @@ windrule_t windrule_evenodd = { // -------------------- circular ---------------------- -edgestyle_t edgestyle_down; -edgestyle_t edgestyle_up; - windstate_t circular_start(windcontext_t*context) { return windstate_nonfilled; diff --git a/lib/gfxpoly/wind.h b/lib/gfxpoly/wind.h index e1926ed8..a07ed642 100644 --- a/lib/gfxpoly/wind.h +++ b/lib/gfxpoly/wind.h @@ -7,7 +7,7 @@ the the (original) segment's y2 is larger than its y1 */ typedef enum {DIR_UP, DIR_DOWN, DIR_UNKNOWN} segment_dir_t; -#define DIR_INVERT(d) ((d)^=(DIR_UP^DIR_DOWN)) +#define DIR_INVERT(d) ((d)^(DIR_UP^DIR_DOWN)) typedef struct _edgestyle { void*internal; |