Date:2011-02-13 06:25:32 (13 years 1 month ago)
Author:Werner Almesberger
Commit:dfc53c781a0f1b16f3a8618093b432bcbc6cb6d6
Message:cameo: new command "stats" to print path statistics

- README: documented the "stats" command
- lang.l, lang.y: added "stats" command
- path.h (path_stats), path.c (path_stats): calculate and print path
statistics
Files: cameo/README (1 diff)
cameo/lang.l (2 diffs)
cameo/lang.y (3 diffs)
cameo/path.c (1 diff)
cameo/path.h (2 diffs)

Change Details

cameo/README
202202Try to reduce the movements made between paths by reordering the paths.
203203Note that this disturbs the order generated by "offset" and should thus
204204not be used on paths that to be executed in a specific sequence.
205
206
207Statistics:
208
209  stats
210
211Prints the number of paths and segments, plus their total length.
cameo/lang.l
22/*
33 * lang.l - Toolpath adaptation language
44 *
5 * Written 2010 by Werner Almesberger
6 * Copyright 2010 by Werner Almesberger
5 * Written 2010-2011 by Werner Almesberger
6 * Copyright 2010-2011 by Werner Almesberger
77 *
88 * This program is free software; you can redistribute it and/or modify
99 * it under the terms of the GNU General Public License as published by
...... 
5050<INITIAL>remainder return TOK_REMAINDER;
5151<INITIAL>reset return TOK_RESET;
5252<INITIAL>rotate return TOK_ROTATE;
53<INITIAL>stats return TOK_STATS;
5354<INITIAL>translate return TOK_TRANSLATE;
5455<INITIAL>z return TOK_Z;
5556
cameo/lang.y
22/*
33 * lang.y - Toolpath adaptation language
44 *
5 * Written 2010 by Werner Almesberger
6 * Copyright 2010 by Werner Almesberger
5 * Written 2010-2011 by Werner Almesberger
6 * Copyright 2010-2011 by Werner Almesberger
77 *
88 * This program is free software; you can redistribute it and/or modify
99 * it under the terms of the GNU General Public License as published by
...... 
187187
188188%token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY
189189%token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET
190%token TOK_ROTATE TOK_TRANSLATE TOK_Z
190%token TOK_ROTATE TOK_STATS TOK_TRANSLATE TOK_Z
191191%token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE
192192%token TOK_DOG TOK_INSIDE
193193
...... 
253253            rotate(paths, $2);
254254            rot += $2;
255255        }
256    | TOK_STATS
257        {
258            path_stats(paths);
259        }
256260    | TOK_TRANSLATE dimen dimen
257261        {
258262            translate(paths, $2, $3, 0);
cameo/path.c
406406        }
407407    return path;
408408}
409
410
411void path_stats(const struct path *path)
412{
413    int paths = 0, segs = 0;
414    double len = 0;
415    const struct point *p;
416
417    while (path) {
418        paths++;
419        for (p = path->first; p; p = p->next) {
420            if (!p->next)
421                continue;
422            segs++;
423            len += hypot(hypot(p->x-p->next->x, p->y-p->next->y),
424                p->z-p->next->z);
425        }
426        path = path->next;
427    }
428    fprintf(stderr, "%d path%s, %d segment%s, %f mm\n",
429        paths, paths == 1 ? "" : "s", segs, segs == 1 ? "" : "s", len);
430}
cameo/path.h
11/*
22 * path.h - Toolpath operations
33 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
4 * Written 2010-2011 by Werner Almesberger
5 * Copyright 2010-2011 Werner Almesberger
66 *
77 * This program is free software; you can redistribute it and/or modify
88 * it under the terms of the GNU General Public License as published by
...... 
3838struct path *path_find_leftmost(struct path *path);
3939void path_free(struct path *path);
4040struct path *path_connect(struct path *path);
41void path_stats(const struct path *path);
4142
4243#endif /* !PATH_H */

Archive Download the corresponding diff file

Branches:
master



interactive