mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
cameo: added KiCad Gerber input and path merging
- Makefile (OBJS): added gerber.o - cameo.c (usage, main): new option -g to process input a KiCad Gerber - gerber.h, gerber.c (gerber_read): parse Gerber files as generated by KiCad - path.h, path.c (path_reverse_inplace, points_eq, attr_eq, path_connect): merge sets of paths with equal endpoints into single paths
This commit is contained in:
65
cameo/path.c
65
cameo/path.c
@@ -147,6 +147,20 @@ struct path *path_reverse(const struct path *path)
|
||||
}
|
||||
|
||||
|
||||
static void path_reverse_inplace(struct path *path)
|
||||
{
|
||||
struct point *points = NULL, *p, *next;
|
||||
|
||||
path->last = path->first;
|
||||
for (p = path->first; p; p = next) {
|
||||
next = p->next;
|
||||
p->next = points;
|
||||
points = p;
|
||||
}
|
||||
path->first = points;
|
||||
}
|
||||
|
||||
|
||||
static struct point *offset_point(const struct point *a, const struct point *b,
|
||||
const struct point *c, double off, int left)
|
||||
{
|
||||
@@ -331,3 +345,54 @@ struct path *path_find_leftmost(struct path *path)
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
|
||||
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 &&
|
||||
a->notch == b->notch;
|
||||
}
|
||||
|
||||
|
||||
struct path *path_connect(struct path *path)
|
||||
{
|
||||
struct path **a, **b;
|
||||
struct path *tmp;
|
||||
|
||||
again:
|
||||
for (a = &path; *a; a = &(*a)->next)
|
||||
for (b = &(*a)->next; *b; b = &(*b)->next) {
|
||||
if (!attr_eq(*a, *b))
|
||||
continue;
|
||||
if (points_eq((*a)->last, (*b)->last))
|
||||
path_reverse_inplace(*b);
|
||||
if (points_eq((*a)->last, (*b)->first)) {
|
||||
(*a)->last->next = (*b)->first->next;
|
||||
(*a)->last = (*b)->last;
|
||||
free((*b)->first);
|
||||
tmp = *b;
|
||||
*b = tmp->next;
|
||||
free(tmp);
|
||||
goto again;
|
||||
}
|
||||
if (points_eq((*a)->first, (*b)->first))
|
||||
path_reverse_inplace(*b);
|
||||
if (points_eq((*a)->first, (*b)->last)) {
|
||||
(*b)->last->next = (*a)->first->next;
|
||||
(*b)->last = (*a)->last;
|
||||
free((*a)->first);
|
||||
tmp = *a;
|
||||
*a = *b;
|
||||
free(tmp);
|
||||
*b = (*b)->next;
|
||||
goto again;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user