Date: | 2011-01-31 23:36:59 (13 years 1 month ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 6947b3a5d1e27d3238182cf822e474ca2ad504ec |
Message: | 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 |
Files: |
cameo/path.c (4 diffs) |
Change Details
cameo/path.c | ||
---|---|---|
1 | 1 | /* |
2 | 2 | * path.c - Toolpath operations |
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 |
... | ... | |
20 | 20 | #include "path.h" |
21 | 21 | |
22 | 22 | |
23 | /* | |
24 | * We allow for a bit of tolerance, to absorb the rounding errors KiCad | |
25 | * produces with designs using a metric grid. | |
26 | */ | |
27 | ||
28 | #define EPSILON_MM 0.006 /* 6 um */ | |
29 | ||
30 | ||
23 | 31 | static void free_points(struct point *points) |
24 | 32 | { |
25 | 33 | struct point *next; |
... | ... | |
77 | 85 | } |
78 | 86 | |
79 | 87 | |
88 | static int points_eq(const struct point *a, const struct point *b) | |
89 | { | |
90 | if (hypot(a->x-b->x, a->y-b->y) > EPSILON_MM) | |
91 | return 0; | |
92 | if (fabs(a->z-b->z) > EPSILON_MM) | |
93 | return 0; | |
94 | return 1; | |
95 | } | |
96 | ||
97 | ||
80 | 98 | static int path_is_closed(const struct path *path) |
81 | 99 | { |
82 | 100 | if (path->first == path->last) |
83 | 101 | return 1; |
84 | return path->first->x == path->last->x && | |
85 | path->first->y == path->last->y && path->first->z == path->last->z; | |
102 | return points_eq(path->first, path->last); | |
86 | 103 | } |
87 | 104 | |
88 | 105 | |
... | ... | |
347 | 364 | } |
348 | 365 | |
349 | 366 | |
350 | static int points_eq(const struct point *a, const struct point *b) | |
351 | { | |
352 | return a->x == b->x && a->y == b->y && a->z == b->z; | |
353 | } | |
354 | ||
355 | ||
356 | 367 | static int attr_eq(const struct path *a, const struct path *b) |
357 | 368 | { |
358 | 369 | return a->r_tool == b->r_tool && a->outside == b->outside && |
Branches:
master