Home | History | Annotate | Download | only in Intersection
      1 // included by CubicParameterization.cpp
      2 // accesses internal functions to validate parameterized coefficients
      3 
      4 #include "Parameterization_Test.h"
      5 
      6 static void parameter_coeffs(const Cubic& cubic, double coeffs[coeff_count]) {
      7 #if USE_SYVESTER
      8     double ax, bx, cx, dx;
      9     if (try_alt)
     10         alt_set_abcd(&cubic[0].x, ax, bx, cx, dx);
     11     else
     12         set_abcd(&cubic[0].x, ax, bx, cx, dx);
     13     double ay, by, cy, dy;
     14     if (try_alt)
     15         alt_set_abcd(&cubic[0].y, ay, by, cy, dy);
     16     else
     17         set_abcd(&cubic[0].y, ay, by, cy, dy);
     18     calc_ABCD(ax, ay, coeffs);
     19     if (!try_alt) calc_bc(dx, bx, cx);
     20     if (!try_alt) calc_bc(dy, by, cy);
     21 #else
     22     double ax = cubic[0].x;
     23     double bx = cubic[1].x;
     24     double cx = cubic[2].x;
     25     double dx = cubic[3].x;
     26     double ay = cubic[0].y;
     27     double by = cubic[1].y;
     28     double cy = cubic[2].y;
     29     double dy = cubic[3].y;
     30     calc_ABCD(ax, bx, cx, dx, ay, by, cy, dy, coeffs);
     31 #endif
     32     for (int index = xx_coeff; index < coeff_count; ++index) {
     33         int procIndex = index - xx_coeff;
     34         coeffs[index] = (*calc_proc[procIndex])(ax, bx, cx, dx, ay, by, cy, dy);
     35     }
     36 }
     37 
     38 bool point_on_parameterized_curve(const Cubic& cubic, const _Point& point) {
     39     double coeffs[coeff_count];
     40     parameter_coeffs(cubic, coeffs);
     41     double xxx = coeffs[xxx_coeff] * point.x * point.x * point.x;
     42     double xxy = coeffs[xxy_coeff] * point.x * point.x * point.y;
     43     double xyy = coeffs[xyy_coeff] * point.x * point.y * point.y;
     44     double yyy = coeffs[yyy_coeff] * point.y * point.y * point.y;
     45     double  xx = coeffs[ xx_coeff] * point.x * point.x;
     46     double  xy = coeffs[ xy_coeff] * point.x * point.y;
     47     double  yy = coeffs[ yy_coeff] * point.y * point.y;
     48     double   x = coeffs[  x_coeff] * point.x;
     49     double   y = coeffs[  y_coeff] * point.y;
     50     double   c = coeffs[  c_coeff];
     51     double sum = xxx + xxy + xyy + yyy + xx + xy + yy + x + y + c;
     52     return approximately_zero(sum);
     53 }
     54