mirror of
git://projects.qi-hardware.com/cae-tools.git
synced 2025-01-03 20:30:14 +02:00
cameo/area.c: move handling of left/right from hit_path to hit_segment
For future extensions.
This commit is contained in:
parent
ebcdfd52ca
commit
7a61482a04
24
cameo/area.c
24
cameo/area.c
@ -155,9 +155,9 @@ 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, int enter,
|
const struct point *a, const struct point *b, double r, int enter,
|
||||||
double *n)
|
int left, double *n)
|
||||||
{
|
{
|
||||||
double dx, dy, d;
|
double dx, dy, nx, ny, nn;
|
||||||
double px, py;
|
double px, py;
|
||||||
double na, nb;
|
double na, nb;
|
||||||
|
|
||||||
@ -167,14 +167,22 @@ static int hit_segment(double fx, double fy, double tx, double ty,
|
|||||||
dx = b->x-a->x;
|
dx = b->x-a->x;
|
||||||
dy = b->y-a->y;
|
dy = b->y-a->y;
|
||||||
|
|
||||||
|
if (left) {
|
||||||
|
nx = dx;
|
||||||
|
ny = dy;
|
||||||
|
} else {
|
||||||
|
nx = -dx;
|
||||||
|
ny = -dy;
|
||||||
|
}
|
||||||
|
|
||||||
/* -dy becomes the x component of the normal vector */
|
/* -dy becomes the x component of the normal vector */
|
||||||
if (enter ? dy < 0 : dy > 0)
|
if (enter ? ny < 0 : ny > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
d = hypot(dx, dy);
|
nn = hypot(nx, ny);
|
||||||
|
|
||||||
px = a->x-dy/d*r;
|
px = a->x-ny/nn*r;
|
||||||
py = a->y+dx/d*r;
|
py = a->y+nx/nn*r;
|
||||||
|
|
||||||
if (!intersect(fx, fy, tx, ty, px, py, dx, dy, &na, &nb))
|
if (!intersect(fx, fy, tx, ty, px, py, dx, dy, &na, &nb))
|
||||||
return 0;
|
return 0;
|
||||||
@ -205,8 +213,8 @@ static int hit_path(double fx, double fy, double tx, double ty,
|
|||||||
if (inside)
|
if (inside)
|
||||||
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, p, p->next,
|
||||||
left ? p : p->next, left ? p->next : p, r, enter, &tmp)) {
|
r, enter, left, &tmp)) {
|
||||||
if (!found || nx > tmp)
|
if (!found || nx > tmp)
|
||||||
nx = tmp;
|
nx = tmp;
|
||||||
found = 1;
|
found = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user