cameo/cameo.c |
1 | 1 | /* |
2 | 2 | * cameo.c - Toolpath adaptation and machine control |
3 | 3 | * |
4 | | * Written 2010 by Werner Almesberger |
5 | | * Copyright 2010 Werner Almesberger |
| 4 | * Written 2010-2011 by Werner Almesberger |
| 5 | * Copyright 2010-2011 Werner Almesberger |
6 | 6 | * |
7 | 7 | * This program is free software; you can redistribute it and/or modify |
8 | 8 | * it under the terms of the GNU General Public License as published by |
... | ... | |
100 | 100 | paths = gerber_read(in, r); |
101 | 101 | else |
102 | 102 | paths = gnuplot_read(in, r); |
103 | | tool_comp_paths(paths, dog_bone, 0); |
| 103 | paths = tool_comp_paths(paths, dog_bone, 0); /* @@@ memory leak */ |
104 | 104 | gnuplot_write(out, paths); |
105 | 105 | |
106 | 106 | return 0; |
cameo/ops.c |
19 | 19 | #include "ops.h" |
20 | 20 | |
21 | 21 | |
22 | | static void tool_comp_1(struct path *path, int inside, int dog_bone) |
| 22 | static struct path *tool_comp_1(const struct path *path, int inside, |
| 23 | int dog_bone) |
23 | 24 | { |
24 | 25 | int left; |
25 | | struct path *new; |
26 | 26 | |
27 | 27 | left = path_tool_is_left(path); |
28 | 28 | if (inside) |
29 | | new = path_offset(path, !left, path->notch); |
| 29 | return path_offset(path, !left, path->notch); |
30 | 30 | else |
31 | | new = path_offset(path, left, path->notch || dog_bone); |
32 | | path_replace(path, new); |
| 31 | return path_offset(path, left, path->notch || dog_bone); |
33 | 32 | } |
34 | 33 | |
35 | 34 | |
36 | | void tool_comp_paths(struct path *paths, int dog_bone, int all_inside) |
| 35 | struct path *tool_comp_paths(const struct path *paths, int dog_bone, |
| 36 | int all_inside) |
37 | 37 | { |
38 | | struct path *leftmost, *path; |
| 38 | const struct path *leftmost, *path; |
| 39 | struct path *new = NULL, **anchor = &new; |
39 | 40 | |
40 | 41 | /* |
41 | 42 | * We don't have an algorithm (yet) that can detect which paths are |
... | ... | |
50 | 51 | |
51 | 52 | leftmost = path_find_leftmost(paths); |
52 | 53 | for (path = paths; path; path = path->next) |
53 | | if (path != leftmost && (all_inside || !path->outside)) |
54 | | tool_comp_1(path, 1, dog_bone); |
| 54 | if (path != leftmost && (all_inside || !path->outside)) { |
| 55 | *anchor = tool_comp_1(path, 1, dog_bone); |
| 56 | anchor = &(*anchor)->next; |
| 57 | } |
55 | 58 | if (!all_inside) |
56 | 59 | for (path = paths; path; path = path->next) |
57 | | if (path != leftmost && path->outside) |
58 | | tool_comp_1(path, 0, dog_bone); |
59 | | tool_comp_1(leftmost, all_inside, dog_bone); |
| 60 | if (path != leftmost && path->outside) { |
| 61 | *anchor = tool_comp_1(path, 0, dog_bone); |
| 62 | anchor = &(*anchor)->next; |
| 63 | } |
| 64 | *anchor = tool_comp_1(leftmost, all_inside, dog_bone); |
| 65 | return new; |
60 | 66 | } |
61 | 67 | |
62 | 68 | |
cameo/ops.h |
17 | 17 | #include "path.h" |
18 | 18 | |
19 | 19 | |
20 | | void tool_comp_paths(struct path *paths, int dog_bone, int all_inside); |
| 20 | struct path *tool_comp_paths(const struct path *paths, int dog_bone, |
| 21 | int all_inside); |
21 | 22 | struct path *try_drill(struct path *path, double d_min, double d_max); |
22 | 23 | struct path *try_mill(struct path *path, double diam, double step, int any); |
23 | 24 | struct path *optimize_paths(struct path *paths); |
cameo/path.c |
134 | 134 | } |
135 | 135 | |
136 | 136 | |
137 | | void path_replace(struct path *old, struct path *new) |
138 | | { |
139 | | struct path *next = old->next; |
140 | | |
141 | | free_points(old->first); |
142 | | free((void *) old->id); |
143 | | *old = *new; |
144 | | old->next = next; |
145 | | free(new); |
146 | | } |
147 | | |
148 | | |
149 | 137 | struct path *path_reverse(const struct path *path) |
150 | 138 | { |
151 | 139 | struct path *new; |
... | ... | |
348 | 336 | } |
349 | 337 | |
350 | 338 | |
351 | | struct path *path_find_leftmost(struct path *path) |
| 339 | const struct path *path_find_leftmost(const struct path *path) |
352 | 340 | { |
353 | 341 | const struct point *p; |
354 | | struct path *best = NULL; |
| 342 | const struct path *best = NULL; |
355 | 343 | double best_x = HUGE_VAL; |
356 | 344 | |
357 | 345 | while (path) { |
cameo/path.h |
32 | 32 | |
33 | 33 | struct path *path_new(double r_tool, const char *id); |
34 | 34 | void path_add(struct path *path, double x, double y, double z); |
35 | | void path_replace(struct path *old, struct path *new); |
36 | 35 | struct path *path_reverse(const struct path *path); |
37 | 36 | int path_tool_is_left(const struct path *path); |
38 | 37 | struct path *path_offset(const struct path *path, int left, int notch); |
39 | | struct path *path_find_leftmost(struct path *path); |
| 38 | const struct path *path_find_leftmost(const struct path *path); |
40 | 39 | void path_free(struct path *path); |
41 | 40 | struct path *path_connect(struct path *path); |
42 | 41 | void path_stats(const struct path *path); |