From ee3a3e6162aeb37a6ea90efb50956e21489163f5 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 5 Jan 2011 22:34:39 -0300 Subject: [PATCH] cameo: array steps can now be specifed as item size plus border - lang.y (align, bbox): moved bounding box calculation to separate function (for sharing) - lang.y: array sizes can specified as the size of the respective dimension of the bounding box plus a border - README: documented use of border size with "array" --- cameo/README | 8 +++++- cameo/lang.y | 72 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 63 insertions(+), 17 deletions(-) diff --git a/cameo/README b/cameo/README index d76a5fc..1419d36 100644 --- a/cameo/README +++ b/cameo/README @@ -109,7 +109,13 @@ The reference point is specified with a number as follows: "array" is used when cutting several copies of the same piece. The first two arguments define the step between pieces while the second two -arguments define how many steps in each direction are taken. +arguments define how many steps in each direction are taken. A step size +can be specified as the total distance, or as the border to add to the +respective dimension of the bounding box of the current path. In the +latter case, the border size is prefix with a plus sign. Example: + +array 37mm 19mm 0 1 +array +3mm +3mm 0 1 "align" moves the toolpath to an absolute position while "array" and "translate" move relative to the current position. The total translation diff --git a/cameo/lang.y b/cameo/lang.y index 5f8a927..1033a11 100644 --- a/cameo/lang.y +++ b/cameo/lang.y @@ -102,26 +102,38 @@ static void ref_pick_xy(int ref, double xa, double ya, double xb, double yb, } +static void bbox(const struct path *path, + double *xa, double *ya, double *xb, double *yb) +{ + const struct point *p; + int first = 1; + + *xa = *ya = *xb = *yb = 0; + + while (path) { + for (p = path->first; p; p = p->next) { + if (first || p->x < *xa) + *xa = p->x; + if (first || p->x > *xb) + *xb = p->x; + if (first || p->y < *ya) + *ya = p->y; + if (first || p->y > *yb) + *yb = p->y; + first = 0; + } + path = path->next; + } +} + + static void align(int ref, double x, double y) { - const struct path *path; - const struct point *p; double xa = 0, ya = 0, xb = 0, yb = 0; double xr, yr, xd, yd; int first = 1; - for (path = paths; path; path = path->next) - for (p = path->first; p; p = p->next) { - if (first || p->x < xa) - xa = p->x; - if (first || p->x > xb) - xb = p->x; - if (first || p->y < ya) - ya = p->y; - if (first || p->y > yb) - yb = p->y; - first = 0; - } + bbox(paths, &xa, &ya, &xb, &yb); ref_pick_xy(ref, xa, ya, xb, yb, &xr, &yr); xd = x-xr; @@ -183,7 +195,7 @@ static struct path **classify(struct path **anchor, struct path *path) %token STRING %type opt_filename -%type dimen number +%type dimen number x_size y_size %type offset_options offset_option %% @@ -210,7 +222,7 @@ command: ref_pick_xy(ref, $3, $4, $5, $6, &x, &y); align(ref, x, y); } - | TOK_ARRAY dimen dimen number number + | TOK_ARRAY x_size y_size number number { double x = $2*$4; double y = $3*$5; @@ -357,6 +369,34 @@ dimen: } ; +x_size: + dimen + { + $$ = $1; + } + | '+' dimen + { + double xa, ya, xb, yb; + + bbox(paths, &xa, &ya, &xb, &yb); + $$ = xb-xa+$2; + } + ; + +y_size: + dimen + { + $$ = $1; + } + | '+' dimen + { + double xa, ya, xb, yb; + + bbox(paths, &xa, &ya, &xb, &yb); + $$ = yb-ya+$2; + } + ; + number: NUM_IMP_MIL {