mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-04-21 12:27:27 +03:00
Accept multiple paths and distinguish between inner paths and the outer path.
- cameo/path.h, cameo/path.c (path_replace): replace a path in a list of paths with a different path - cameo/path.h, cameo/path.c (path_find_leftmost): find the leftmost path in a list of paths - cameo/path.h, cameo/path.c (path_free): move freeing of points to separate function free_points, for sharing with path_replace - cameo/cameo.c (main): move path processing to new function process_paths - cameo/cameo.c (process_paths): treat the leftmost path a outside path and process it last. Treat all others as inside paths.
This commit is contained in:
50
cameo/path.c
50
cameo/path.c
@@ -20,6 +20,25 @@
|
||||
#include "path.h"
|
||||
|
||||
|
||||
static void free_points(struct point *points)
|
||||
{
|
||||
struct point *next;
|
||||
|
||||
while (points) {
|
||||
next = points->next;
|
||||
free(points);
|
||||
points = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void path_free(struct path *path)
|
||||
{
|
||||
free_points(path->first);
|
||||
free(path);
|
||||
}
|
||||
|
||||
|
||||
struct path *path_new(double r_tool)
|
||||
{
|
||||
struct path *path;
|
||||
@@ -77,6 +96,17 @@ void path_add(struct path *path, double x, double y, double z)
|
||||
}
|
||||
|
||||
|
||||
void path_replace(struct path *old, struct path *new)
|
||||
{
|
||||
struct path *next = old->next;
|
||||
|
||||
free_points(old->first);
|
||||
*old = *new;
|
||||
old->next = next;
|
||||
free(new);
|
||||
}
|
||||
|
||||
|
||||
struct path *path_reverse(const struct path *path)
|
||||
{
|
||||
struct path *new;
|
||||
@@ -265,14 +295,20 @@ struct path *path_offset(const struct path *path, int left, int notch)
|
||||
}
|
||||
|
||||
|
||||
void path_free(struct path *path)
|
||||
struct path *path_find_leftmost(struct path *path)
|
||||
{
|
||||
struct point *next;
|
||||
const struct point *p;
|
||||
struct path *best = NULL;
|
||||
double best_x = HUGE_VAL;
|
||||
|
||||
while (path->first) {
|
||||
next = path->first->next;
|
||||
free(path->first);
|
||||
path->first = next;
|
||||
while (path) {
|
||||
for (p = path->first; p; p = p->next)
|
||||
if (p->x < best_x) {
|
||||
best = path;
|
||||
best_x = p->x;
|
||||
break;
|
||||
}
|
||||
path = path->next;
|
||||
}
|
||||
free(path);
|
||||
return best;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user