From dfc53c781a0f1b16f3a8618093b432bcbc6cb6d6 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 13 Feb 2011 02:25:32 -0300 Subject: [PATCH] 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 --- cameo/README | 7 +++++++ cameo/lang.l | 5 +++-- cameo/lang.y | 10 +++++++--- cameo/path.c | 22 ++++++++++++++++++++++ cameo/path.h | 5 +++-- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/cameo/README b/cameo/README index 1419d36..01cb830 100644 --- a/cameo/README +++ b/cameo/README @@ -202,3 +202,10 @@ Tool path optimization: Try to reduce the movements made between paths by reordering the paths. Note that this disturbs the order generated by "offset" and should thus not be used on paths that to be executed in a specific sequence. + + +Statistics: + + stats + +Prints the number of paths and segments, plus their total length. diff --git a/cameo/lang.l b/cameo/lang.l index 9799082..d7e841e 100644 --- a/cameo/lang.l +++ b/cameo/lang.l @@ -2,8 +2,8 @@ /* * lang.l - Toolpath adaptation language * - * Written 2010 by Werner Almesberger - * Copyright 2010 by Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -50,6 +50,7 @@ NUM -?[0-9]+\.?[0-9]* remainder return TOK_REMAINDER; reset return TOK_RESET; rotate return TOK_ROTATE; +stats return TOK_STATS; translate return TOK_TRANSLATE; z return TOK_Z; diff --git a/cameo/lang.y b/cameo/lang.y index 1033a11..efd0e29 100644 --- a/cameo/lang.y +++ b/cameo/lang.y @@ -2,8 +2,8 @@ /* * lang.y - Toolpath adaptation language * - * Written 2010 by Werner Almesberger - * Copyright 2010 by Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 by Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -187,7 +187,7 @@ static struct path **classify(struct path **anchor, struct path *path) %token TOK_ALIGN TOK_ARRAY TOK_CLEAR TOK_DRILL TOK_EMPTY %token TOK_MILL TOK_OFFSET TOK_OPTIMIZE TOK_REMAINDER TOK_RESET -%token TOK_ROTATE TOK_TRANSLATE TOK_Z +%token TOK_ROTATE TOK_STATS TOK_TRANSLATE TOK_Z %token TOK_APPEND TOK_GERBER TOK_GNUPLOT TOK_EXCELLON TOK_WRITE %token TOK_DOG TOK_INSIDE @@ -253,6 +253,10 @@ command: rotate(paths, $2); rot += $2; } + | TOK_STATS + { + path_stats(paths); + } | TOK_TRANSLATE dimen dimen { translate(paths, $2, $3, 0); diff --git a/cameo/path.c b/cameo/path.c index fa7f981..90a0006 100644 --- a/cameo/path.c +++ b/cameo/path.c @@ -406,3 +406,25 @@ again: } return path; } + + +void path_stats(const struct path *path) +{ + int paths = 0, segs = 0; + double len = 0; + const struct point *p; + + while (path) { + paths++; + for (p = path->first; p; p = p->next) { + if (!p->next) + continue; + segs++; + len += hypot(hypot(p->x-p->next->x, p->y-p->next->y), + p->z-p->next->z); + } + path = path->next; + } + fprintf(stderr, "%d path%s, %d segment%s, %f mm\n", + paths, paths == 1 ? "" : "s", segs, segs == 1 ? "" : "s", len); +} diff --git a/cameo/path.h b/cameo/path.h index 23bcafd..9751ab9 100644 --- a/cameo/path.h +++ b/cameo/path.h @@ -1,8 +1,8 @@ /* * path.h - Toolpath operations * - * Written 2010 by Werner Almesberger - * Copyright 2010 Werner Almesberger + * Written 2010-2011 by Werner Almesberger + * Copyright 2010-2011 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,5 +38,6 @@ struct path *path_offset(const struct path *path, int left, int notch); struct path *path_find_leftmost(struct path *path); void path_free(struct path *path); struct path *path_connect(struct path *path); +void path_stats(const struct path *path); #endif /* !PATH_H */