Root/cameo/path.h

1/*
2 * path.h - Toolpath operations
3 *
4 * Written 2010-2012, 2015 by Werner Almesberger
5 * Copyright 2010-2012, 2015 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef PATH_H
15#define PATH_H
16
17#include <math.h>
18
19
20struct point {
21    double x, y, z; /* mm */
22    struct point *next;
23};
24
25struct path {
26    struct point *first, *last;
27    double r_tool; /* mm */
28    int outside; /* non-zero to mark path as an outside edge */
29    int notch; /* non-zero to enable dog-boning for path */
30    const char *id; /* identifier assigned by generator */
31    struct path *next;
32};
33
34
35/*
36 * We allow for a bit of tolerance, to absorb the rounding errors KiCad
37 * produces with designs using a metric grid.
38 */
39
40#define EPSILON_MM 0.006 /* 6 um */
41
42
43static inline int points_eq(const struct point *a, const struct point *b)
44{
45    if (hypot(a->x-b->x, a->y-b->y) > EPSILON_MM)
46        return 0;
47    if (fabs(a->z-b->z) > EPSILON_MM)
48        return 0;
49    return 1;
50}
51
52
53struct path *path_new(double r_tool, const char *id);
54struct path *path_from(const struct path *old);
55void path_add(struct path *path, double x, double y, double z);
56struct path *path_reverse(const struct path *path);
57struct path *path_clone(const struct path *path);
58int path_is_closed(const struct path *path);
59int path_tool_is_left(const struct path *path);
60struct path *path_offset(const struct path *path, int left, int notch);
61const struct path *path_find_leftmost(const struct path *path);
62int path_is_inside(const struct path *a, const struct path *b);
63void path_free(struct path *path);
64struct path *path_connect(struct path *path);
65void path_stats(const struct path *path);
66
67#endif /* !PATH_H */
68

Archive Download this file

Branches:
master



interactive