diff --git a/cameo/path.c b/cameo/path.c index c8a6f42..fa7f981 100644 --- a/cameo/path.c +++ b/cameo/path.c @@ -1,8 +1,8 @@ /* * path.c - 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 @@ -20,6 +20,14 @@ #include "path.h" +/* + * We allow for a bit of tolerance, to absorb the rounding errors KiCad + * produces with designs using a metric grid. + */ + +#define EPSILON_MM 0.006 /* 6 um */ + + static void free_points(struct point *points) { struct point *next; @@ -77,12 +85,21 @@ static struct point *clone_point(struct point *p) } +static int points_eq(const struct point *a, const struct point *b) +{ + if (hypot(a->x-b->x, a->y-b->y) > EPSILON_MM) + return 0; + if (fabs(a->z-b->z) > EPSILON_MM) + return 0; + return 1; +} + + static int path_is_closed(const struct path *path) { if (path->first == path->last) return 1; - return path->first->x == path->last->x && - path->first->y == path->last->y && path->first->z == path->last->z; + return points_eq(path->first, path->last); } @@ -347,12 +364,6 @@ struct path *path_find_leftmost(struct path *path) } -static int points_eq(const struct point *a, const struct point *b) -{ - return a->x == b->x && a->y == b->y && a->z == b->z; -} - - static int attr_eq(const struct path *a, const struct path *b) { return a->r_tool == b->r_tool && a->outside == b->outside &&