1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-04-21 12:27:27 +03:00

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"
This commit is contained in:
Werner Almesberger
2011-01-05 22:34:39 -03:00
parent 6f30bab648
commit ee3a3e6162
2 changed files with 63 additions and 17 deletions

View File

@@ -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 <str> STRING
%type <str> opt_filename
%type <num> dimen number
%type <num> dimen number x_size y_size
%type <oopt> 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
{