From 18c9477137363d130e8968323cb3eaf0f1eac92f Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Mon, 19 Mar 2012 00:26:41 -0300 Subject: [PATCH] cameo: "area" now works on Z layers individually (untested) --- cameo/README | 3 +++ cameo/area.c | 49 +++++++++++++++++++++++++++++++++++++------------ cameo/area.h | 2 +- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/cameo/README b/cameo/README index 724cdb2..0af9613 100644 --- a/cameo/README +++ b/cameo/README @@ -170,6 +170,9 @@ what "offset" does. The overlap is the distance by which the areas cleared by parallel paths should overlap. +If the current paths have different Z coordinates, each level is +processed separately. + Drill/mill conversion: diff --git a/cameo/area.c b/cameo/area.c index 3d2ff19..1b23429 100644 --- a/cameo/area.c +++ b/cameo/area.c @@ -16,7 +16,6 @@ * outlines without cutting into anything it's not supposed to. */ -#include #include #include #include @@ -209,18 +208,20 @@ static int hit_path(double fx, double fy, double tx, double ty, static const struct path **subordinates(const struct path *paths, - const struct path *path) + const struct path *path, double z) { const struct path **sub, **w, **a, **b;; const struct path *p; int n = 0; for (p = paths; p; p = p->next) - n++; + if (p->first && p->first->z == z) + n++; sub = alloc_size(sizeof(struct path *)*n); w = sub; for (p = paths; p; p = p->next) - if (p != path && is_inside(p, path) && !is_inside(path, p)) + if (p != path && p->first && p->first->z == z && + is_inside(p, path) && !is_inside(path, p)) *w++ = p; *w = NULL; for (a = sub; a != w; a++) @@ -283,7 +284,7 @@ static void add_outline(const struct path *path, int inside, struct path **res) static void fill_path(const struct path *paths, const struct path *path, - double r_tool, double overlap, struct path **res) + double z, double r_tool, double overlap, struct path **res) { const struct path **sub, **s; const struct path **sub2, **s2; @@ -292,7 +293,7 @@ static void fill_path(const struct path *paths, const struct path *path, if (!bbox(path, &xa, &ya, &xb, &yb)) return; - sub = subordinates(paths, path); + sub = subordinates(paths, path, z); xa += r_tool; ya += 3*r_tool-overlap; xb -= r_tool; @@ -302,9 +303,9 @@ static void fill_path(const struct path *paths, const struct path *path, 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); + sub2 = subordinates(paths, *s, z); for (s2 = sub2; *s2; s2++) - fill_path(paths, *s2, r_tool, overlap, res); + fill_path(paths, *s2, z, r_tool, overlap, res); free(sub2); add_outline(*s, 0, res); } @@ -313,12 +314,36 @@ static void fill_path(const struct path *paths, const struct path *path, } -struct path *area(const struct path *path, double overlap) +struct path *area(const struct path *paths, double overlap) { struct path *res = NULL; + double z = HUGE_VAL, best_x, x; + const struct path *path, *best; + const struct point *p; - if (!path) + if (!paths) return NULL; - fill_path(path, path_find_leftmost(path), path->r_tool, overlap, &res); - return res; + while (1) { + best = NULL; + best_x = HUGE_VAL; + for (path = paths; path; path = path->next) { + if (!path->first) + continue; + if (path->first->z >= z) + continue; + x = HUGE_VAL; + for (p = path->first; p; p = p->next) + if (p->x < x) + x = p->x; + if (best && best->first->z >= path->first->z && + x >= best_x) + continue; + best = path; + best_x = x; + } + if (!best) + return res; + z = best->first->z; + fill_path(paths, best, z, best->r_tool, overlap, &res); + } } diff --git a/cameo/area.h b/cameo/area.h index d68de2f..9915a15 100644 --- a/cameo/area.h +++ b/cameo/area.h @@ -18,6 +18,6 @@ #include "path.h" -struct path *area(const struct path *path, double overlap); +struct path *area(const struct path *paths, double overlap); #endif /* !AREA_H */