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 | ||
---|---|---|
202 | 202 | Try to reduce the movements made between paths by reordering the paths. |
203 | 203 | Note that this disturbs the order generated by "offset" and should thus |
204 | 204 | not be used on paths that to be executed in a specific sequence. |
205 | ||
206 | ||
207 | Statistics: | |
208 | ||
209 | stats | |
210 | ||
211 | Prints the number of paths and segments, plus their total length. |
cameo/lang.l | ||
---|---|---|
2 | 2 | /* |
3 | 3 | * lang.l - Toolpath adaptation language |
4 | 4 | * |
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 | |
7 | 7 | * |
8 | 8 | * This program is free software; you can redistribute it and/or modify |
9 | 9 | * it under the terms of the GNU General Public License as published by |
... | ... | |
50 | 50 | <INITIAL>remainder return TOK_REMAINDER; |
51 | 51 | <INITIAL>reset return TOK_RESET; |
52 | 52 | <INITIAL>rotate return TOK_ROTATE; |
53 | <INITIAL>stats return TOK_STATS; | |
53 | 54 | <INITIAL>translate return TOK_TRANSLATE; |
54 | 55 | <INITIAL>z return TOK_Z; |
55 | 56 |
cameo/lang.y | ||
---|---|---|
2 | 2 | /* |
3 | 3 | * lang.y - Toolpath adaptation language |
4 | 4 | * |
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 | |
7 | 7 | * |
8 | 8 | * This program is free software; you can redistribute it and/or modify |
9 | 9 | * it under the terms of the GNU General Public License as published by |
... | ... | |
187 | 187 | |
188 | 188 | %token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY |
189 | 189 | %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 | |
191 | 191 | %token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE |
192 | 192 | %token TOK_DOG TOK_INSIDE |
193 | 193 | |
... | ... | |
253 | 253 | rotate(paths, $2); |
254 | 254 | rot += $2; |
255 | 255 | } |
256 | | TOK_STATS | |
257 | { | |
258 | path_stats(paths); | |
259 | } | |
256 | 260 | | TOK_TRANSLATE dimen dimen |
257 | 261 | { |
258 | 262 | translate(paths, $2, $3, 0); |
cameo/path.c | ||
---|---|---|
406 | 406 | } |
407 | 407 | return path; |
408 | 408 | } |
409 | ||
410 | ||
411 | void 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 | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * path.h - Toolpath operations |
3 | 3 | * |
4 | * Written 2010 by Werner Almesberger | |
5 | * Copyright 2010 Werner Almesberger | |
4 | * Written 2010-2011 by Werner Almesberger | |
5 | * Copyright 2010-2011 Werner Almesberger | |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
38 | 38 | struct path *path_find_leftmost(struct path *path); |
39 | 39 | void path_free(struct path *path); |
40 | 40 | struct path *path_connect(struct path *path); |
41 | void path_stats(const struct path *path); | |
41 | 42 | |
42 | 43 | #endif /* !PATH_H */ |
Branches:
master