1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2025-04-21 12:27:27 +03:00

cameo/: new commands "remove" and "keep" for path filtering (untested)

This commit is contained in:
Werner Almesberger
2012-06-12 12:32:08 -03:00
parent 3ee5b1aa31
commit e69fa24133
7 changed files with 95 additions and 6 deletions

View File

@@ -153,3 +153,41 @@ struct path *reverse_paths(const struct path *paths)
}
return res;
}
static int select_path(const struct path *path, double xa, double ya,
double xb, double yb, int inside)
{
const struct point *p;
for (p = path->first; p; p = p->next) {
if (p->x >= xa && p->x <= xb && p->y >= ya && p->y <= yb) {
if (!inside)
return 0;
} else {
if (inside)
return 0;
}
}
return 1;
}
struct path *select_paths(const struct path *paths, double xa, double ya,
double xb, double yb, int inside)
{
struct path *res = NULL, **last = &res;
if (xa > xb)
return select_paths(paths, xb, ya, xa, yb, inside);
if (ya > yb)
return select_paths(paths, xa, yb, xb, ya, inside);
while (paths) {
if (select_path(paths, xa, ya, xb, yb, inside)) {
*last = path_clone(paths);
last = &(*last)->next;
}
paths = paths->next;
}
return res;
}