From 382d14dcbb6970095779ede1847996b31c25ae1a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 12 Jun 2012 14:01:55 -0300 Subject: [PATCH] cameo/path.c: move assert(path_is_closed) into function and improve diagnostic It's often hard to find an offending path. To help with this, we now print the start and end coordinates. --- cameo/path.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cameo/path.c b/cameo/path.c index c2a4707..f8a8515 100644 --- a/cameo/path.c +++ b/cameo/path.c @@ -106,6 +106,17 @@ static int path_is_closed(const struct path *path) } +static void assert_path_is_closed(const struct path *path) +{ + if (path_is_closed(path)) + return; + fprintf(stderr, "path from (%g, %g, %g) to (%g, %g, %g) is open\n", + path->first->x, path->first->y, path->first->z, + path->last->x, path->last->y, path->last->z); + abort(); +} + + static void path_add_point(struct path *path, struct point *p) { if (path->last && @@ -284,7 +295,8 @@ int path_tool_is_left(const struct path *path) const struct point *prev, *p, *next; double a = 0; - assert(path_is_closed(path)); + + assert_path_is_closed(path); prev = path->first; for (p = path->first->next; p; p = p->next) { next = p->next ? p->next : path->first->next; @@ -335,7 +347,7 @@ struct path *path_offset(const struct path *path, int left, int notch) struct point *n, *n2; int dog; - assert(path_is_closed(path)); + assert_path_is_closed(path); if (path->first == path->last) return circle(path->first->x, path->first->y, path->first->z, path->r_tool, path->r_tool, 0.1, path->id);