diff --git a/cameo/area.c b/cameo/area.c index 0995e12..53c58df 100644 --- a/cameo/area.c +++ b/cameo/area.c @@ -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, - double cx, double cy, double r, double *n) + double cx, double cy, double r, int enter, double *n) { double dx = cx-ax; double dy = cy-ay; double a = bx*bx+by*by; double b = -2*bx*dx-2*by*dy; 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; if (d < 0) return 0; 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; n1 = (-b+d)/2/a; @@ -146,6 +153,7 @@ static int touch(double ax, double ay, double bx, double by, return 1; } return 0; +#endif } @@ -179,11 +187,11 @@ printf(" seg (%g,%g)+(%g,%g) -> (%g,%g)-(%g,%g)\n", return 0; printf("\tna %g (%g) nb %g (%g)\n", na, fx+tx*na, nb, fx+tx*nb); 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; } 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; } if (na <= 0 || na >= 1)