1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-01-03 22:00:14 +02:00

cameo: allow for rounding errors KiCad produces with a metric grid

- cameo/path.c (path_is_closed): use points_eq instead of open-coding the
  comparison
- cameo//path.c (EPSILON_MM, points_eq): consider two points as equal if
  their projections on the xy plane are less than EPSILON_MM apart and
  their z positions don't differ by more than the same distance
This commit is contained in:
Werner Almesberger 2011-01-31 19:36:59 -03:00
parent 4b717cadc6
commit 6947b3a5d1

View File

@ -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 &&