1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 04:23:55 +02:00

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.
This commit is contained in:
Werner Almesberger 2012-03-18 19:47:02 -03:00
parent 5a599e14f6
commit b607816f95

View File

@ -10,6 +10,11 @@
* (at your option) any later version. * (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 <stdio.h> #include <stdio.h>
#include <stddef.h> #include <stddef.h>
@ -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, 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 dx, dy, d;
double px, py; double px, py;
@ -158,6 +164,12 @@ printf(" seg (%g,%g)+(%g,%g) -> (%g,%g)-(%g,%g)\n",
dx = b->x-a->x; dx = b->x-a->x;
dy = b->y-a->y; dy = b->y-a->y;
if (enter && dy < 0)
return 0;
if (!enter && dy > 0)
return 0;
d = hypot(dx, dy); d = hypot(dx, dy);
px = a->x-dy/d*r; px = a->x-dy/d*r;
@ -194,7 +206,7 @@ static int hit_path(double fx, double fy, double tx, double ty,
left = !left; left = !left;
for (p = path->first; p != path->last; p = p->next) { for (p = path->first; p != path->last; p = p->next) {
if (hit_segment(fx, fy, tx, ty, 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) if (!found || nx > tmp)
nx = tmp; nx = tmp;
found = 1; found = 1;