From 5a599e14f6e5ef17ab80ed09148fbb949ecf5bf6 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 18 Mar 2012 17:57:04 -0300 Subject: [PATCH] cameo: don't duplicate paths already cleared by the outline Also pass information on whether we're about to enter or leave a polygon. --- cameo/area.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cameo/area.c b/cameo/area.c index 17a8ccf..953f472 100644 --- a/cameo/area.c +++ b/cameo/area.c @@ -182,7 +182,7 @@ printf("\tna %g (%g) nb %g (%g)\n", na, fx+tx*na, nb, fx+tx*nb); static int hit_path(double fx, double fy, double tx, double ty, - const struct path *path, int inside, double r, double *x) + const struct path *path, int inside, int enter, double r, double *x) { const struct point *p; int left; @@ -234,7 +234,8 @@ static const struct path **subordinates(const struct path *paths, static void do_line(const struct path *path, const struct path **sub, - double xa, double xb, double y, double r_tool, struct path **res) + double xa, double xb, double y, double r_tool, double overlap, + struct path **res) { const struct path *last = path; const struct path **s; @@ -242,25 +243,27 @@ static void do_line(const struct path *path, const struct path **sub, double x, next; printf(" y=%g\n", y); - if (!hit_path(xa-3*r_tool, y, xb, y, last, 1, r_tool, &x)) + if (!hit_path(xa-3*r_tool, y, xb, y, last, 1, 0, r_tool, &x)) return; while (1) { printf(" x=%g\n", x); next = xb; last = NULL; - if (hit_path(x, y, xb, y, path, 1, r_tool, &next)) + if (hit_path(x, y, xb, y, path, 1, 1, r_tool, &next)) last = path; for (s = sub; *s; s++) - if (hit_path(x, y, next, y, *s, 0, r_tool, &next)) + if (hit_path(x, y, next, y, *s, 0, 1, r_tool, &next)) last = *s; - new = path_new(r_tool, ""); - path_add(new, x, y, path->first->z); - path_add(new, next, y, path->first->z); - new->next = *res; - *res = new; + if (next-x > 2*r_tool-2*overlap) { + new = path_new(r_tool, ""); + path_add(new, x, y, path->first->z); + path_add(new, next, y, path->first->z); + new->next = *res; + *res = new; + } if (!last) return; - if (!hit_path(next+EPSILON, y, xb, y, last, last == path, + if (!hit_path(next+EPSILON, y, xb, y, last, last == path, 0, r_tool, &x)) return; } @@ -291,14 +294,14 @@ static void fill_path(const struct path *paths, const struct path *path, return; sub = subordinates(paths, path); xa += r_tool; - ya += r_tool; + ya += 3*r_tool-overlap; xb -= r_tool; - yb -= r_tool; + yb -= 3*r_tool-overlap; n = ceil((yb-ya)/(2*r_tool-overlap)); printf("x[%g:%g] y[%g:%g] n=%d\n", xa, xb, ya, yb, n); for (i = 0; i <= n; i++) - do_line(path, sub, xa, xb, ya+(yb-ya)*((double) i/n), r_tool, - res); + do_line(path, sub, xa, xb, ya+(yb-ya)*((double) i/n), + r_tool, overlap, res); for (s = sub; *s; s++) { sub2 = subordinates(paths, *s); for (s2 = sub2; *s2; s2++)