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

cameo/: new command "flip" to flip paths on the X or Y axis

This commit is contained in:
Werner Almesberger
2012-08-23 09:04:44 -03:00
parent c73509dacc
commit a030eff963
3 changed files with 71 additions and 2 deletions

View File

@@ -80,6 +80,43 @@ static void rotate(struct path *list, double angle)
}
static void flip(struct path *list, enum axis axis, double center)
{
const struct path *path;
struct point *p;
for (path = list; path; path = path->next)
for (p = path->first; p; p = p->next) {
if (axis == axis_x)
p->x = 2*center-p->x;
else
p->y = 2*center-p->y;
}
}
static void flip_center(struct path *list, enum axis axis)
{
double min = 0, max = 0;
double coord;
const struct path *path;
const struct point *p;
int first = 1;
for (path = list; path; path = path->next)
for (p = path->first; p; p = p->next) {
coord = axis == axis_x ? p->x : p->y;
if (first || coord < min)
min = coord;
if (first || coord > max)
max = coord;
first = 0;
}
flip(list, axis, (min+max)/2);
}
static double ref_pick_1(int ref, double a, double b)
{
switch (ref) {
@@ -184,14 +221,19 @@ static struct path **classify(struct path **anchor, struct path *path)
OO_DOG = 1 << 0,
OO_INSIDE = 1 << 1,
} oopt;
enum axis {
axis_x,
axis_y
} axis;
};
%token TOK_ALIGN TOK_AREA TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
%token TOK_KEEP TOK_MILL TOK_OFFSET TOK_OPTIMIZE
%token TOK_FLIP TOK_KEEP TOK_MILL TOK_OFFSET TOK_OPTIMIZE
%token TOK_OUTSIDE TOK_REMAINDER
%token TOK_REMOVE TOK_RESET
%token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_TRANSLATE TOK_Z
%token TOK_REVERSE TOK_ROTATE TOK_STATS TOK_TRANSLATE
%token TOK_X TOK_Y TOK_Z
%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
%token TOK_DOG TOK_INSIDE TOK_ANY
@@ -202,6 +244,7 @@ static struct path **classify(struct path **anchor, struct path *path)
%type <num> dimen number x_size y_size
%type <flag> opt_any
%type <oopt> offset_options offset_option
%type <axis> axis
%%
@@ -283,6 +326,14 @@ command:
rotate(paths, $2);
rot += $2;
}
| TOK_FLIP axis
{
flip_center(paths, $2);
}
| TOK_FLIP axis dimen
{
flip(paths, $2, $3);
}
| TOK_STATS
{
path_stats(paths);
@@ -489,6 +540,17 @@ offset_option:
}
;
axis:
TOK_X
{
$$ = axis_x;
}
| TOK_Y
{
$$ = axis_y;
}
;
opt_comma:
| ','
;