From b607816f952c31182b2acfbd0ef3b0ca38246789 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 18 Mar 2012 19:47:02 -0300 Subject: [PATCH] cameo/area (hit_segment): only consider vectors pointing in the right direction This way we avoid false positives, such as exit points while looking for an entry. --- cameo/area.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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;