diff --git a/cameo/area.c b/cameo/area.c index cf58116..364f4a5 100644 --- a/cameo/area.c +++ b/cameo/area.c @@ -84,6 +84,29 @@ static int is_inside(const struct path *a, const struct path *b) /* * Solve * + * ax+by = e + * cx+dy = f + * + * with Cramer's rule: + * http://en.wikipedia.org/wiki/Cramer's_rule + */ + +static int cramer2(double a, double b, double c, double d, double e, double f, + double *x, double *y) +{ + double det; + + det = a*d-b*c; + if (fabs(det) < EPSILON) + return 0; + *x = (e*d-b*f)/det; + *y = (a*f-e*c)/det; + return 1; +} + + +/* + * Solve * ax+na*bx = cx+nb*dx * ay+na*by = cy+nb*dy * @@ -91,23 +114,12 @@ static int is_inside(const struct path *a, const struct path *b) * * na*bx + nb*-dx = cx-ax * na*by + nb*-dy = cy-ay - * - * which we the solve with Cramer's rule: - * http://en.wikipedia.org/wiki/Cramer's_rule */ static int intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, double *na, double *nb) { - double det; - - det = dx*by-bx*dy; - if (fabs(det) < EPSILON) - return 0; - - *na = (dx*(cy-ay)-dy*(cx-ax))/det; - *nb = (bx*(cy-ay)-by*(cx-ax))/det; - return 1; + return cramer2(bx, -dx, by, -dy, cx-ax, cy-ay, na, nb); }