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

cameo/area.c (touch): also consider whether we're looking for entry/exit

This commit is contained in:
Werner Almesberger 2012-03-18 20:15:50 -03:00
parent b607816f95
commit 6fbdfd7120

View File

@ -121,19 +121,26 @@ static int intersect(double ax, double ay, double bx, double by,
*/ */
static int touch(double ax, double ay, double bx, double by, static int touch(double ax, double ay, double bx, double by,
double cx, double cy, double r, double *n) double cx, double cy, double r, int enter, double *n)
{ {
double dx = cx-ax; double dx = cx-ax;
double dy = cy-ay; double dy = cy-ay;
double a = bx*bx+by*by; double a = bx*bx+by*by;
double b = -2*bx*dx-2*by*dy; double b = -2*bx*dx-2*by*dy;
double c = dx*dx+dy*dy-r*r; double c = dx*dx+dy*dy-r*r;
double d, n0, n1; // double d, n0, n1;
double d, tmp;
d = b*b-4*a*c; d = b*b-4*a*c;
if (d < 0) if (d < 0)
return 0; return 0;
d = sqrt(d); d = sqrt(d);
tmp = enter ? (-b-d)/2/a : (-b+d)/2/a;
if (tmp <= 0 || tmp >= 1)
return 0;
*n = tmp;
return 1;
#if 0
n0 = (-b-d)/2/a; n0 = (-b-d)/2/a;
n1 = (-b+d)/2/a; n1 = (-b+d)/2/a;
@ -146,6 +153,7 @@ static int touch(double ax, double ay, double bx, double by,
return 1; return 1;
} }
return 0; return 0;
#endif
} }
@ -179,11 +187,11 @@ printf(" seg (%g,%g)+(%g,%g) -> (%g,%g)-(%g,%g)\n",
return 0; return 0;
printf("\tna %g (%g) nb %g (%g)\n", na, fx+tx*na, nb, fx+tx*nb); printf("\tna %g (%g) nb %g (%g)\n", na, fx+tx*na, nb, fx+tx*nb);
if (nb <= 0) { if (nb <= 0) {
if (!touch(fx, fy, tx, ty, a->x, a->y, r, &na)) if (!touch(fx, fy, tx, ty, a->x, a->y, r, enter, &na))
return 0; return 0;
} }
if (nb >= 1) { if (nb >= 1) {
if (!touch(fx, fy, tx, ty, b->x, b->y, r, &na)) if (!touch(fx, fy, tx, ty, b->x, b->y, r, enter, &na))
return 0; return 0;
} }
if (na <= 0 || na >= 1) if (na <= 0 || na >= 1)