diff --git a/cameo/area.c b/cameo/area.c index 953f472..0995e12 100644 --- a/cameo/area.c +++ b/cameo/area.c @@ -10,6 +10,11 @@ * (at your option) any later version. */ +/* + * We use the following requirement to simplify toolpath generation: the + * outlines must be designed such that the tool can pass along all the + * outlines without cutting into anything it's not supposed to. + */ #include #include @@ -145,7 +150,8 @@ static int touch(double ax, double ay, double bx, double by, static int hit_segment(double fx, double fy, double tx, double ty, - const struct point *a, const struct point *b, double r, double *n) + const struct point *a, const struct point *b, double r, int enter, + double *n) { double dx, dy, d; double px, py; @@ -158,6 +164,12 @@ printf(" seg (%g,%g)+(%g,%g) -> (%g,%g)-(%g,%g)\n", dx = b->x-a->x; dy = b->y-a->y; + + if (enter && dy < 0) + return 0; + if (!enter && dy > 0) + return 0; + d = hypot(dx, dy); px = a->x-dy/d*r; @@ -194,7 +206,7 @@ static int hit_path(double fx, double fy, double tx, double ty, left = !left; for (p = path->first; p != path->last; p = p->next) { if (hit_segment(fx, fy, tx, ty, - left ? p : p->next, left ? p->next : p, r, &tmp)) { + left ? p : p->next, left ? p->next : p, r, enter, &tmp)) { if (!found || nx > tmp) nx = tmp; found = 1;