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