caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 1 | // included by CubicParameterization.cpp |
| 2 | // accesses internal functions to validate parameterized coefficients |
| 3 | |
| 4 | static void parameter_coeffs(const Cubic& cubic, double coeffs[coeff_count]) { |
| 5 | double ax, bx, cx, dx; |
| 6 | if (try_alt) |
| 7 | alt_set_abcd(&cubic[0].x, ax, bx, cx, dx); |
| 8 | else |
| 9 | set_abcd(&cubic[0].x, ax, bx, cx, dx); |
| 10 | double ay, by, cy, dy; |
| 11 | if (try_alt) |
| 12 | alt_set_abcd(&cubic[0].y, ay, by, cy, dy); |
| 13 | else |
| 14 | set_abcd(&cubic[0].y, ay, by, cy, dy); |
| 15 | calc_ABCD(ax, ay, coeffs); |
| 16 | if (!try_alt) calc_bc(dx, bx, cx); |
| 17 | if (!try_alt) calc_bc(dy, by, cy); |
| 18 | for (int index = xx_coeff; index < coeff_count; ++index) { |
| 19 | int procIndex = index - xx_coeff; |
| 20 | coeffs[index] = (*calc_proc[procIndex])(ax, bx, cx, dx, ay, by, cy, dy); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | bool point_on_parameterized_curve(const Cubic& cubic, const _Point& point) { |
| 25 | double coeffs[coeff_count]; |
| 26 | parameter_coeffs(cubic, coeffs); |
| 27 | double xxx = coeffs[xxx_coeff] * point.x * point.x * point.x; |
| 28 | double xxy = coeffs[xxy_coeff] * point.x * point.x * point.y; |
| 29 | double xyy = coeffs[xyy_coeff] * point.x * point.y * point.y; |
| 30 | double yyy = coeffs[yyy_coeff] * point.y * point.y * point.y; |
| 31 | double xx = coeffs[ xx_coeff] * point.x * point.x; |
| 32 | double xy = coeffs[ xy_coeff] * point.x * point.y; |
| 33 | double yy = coeffs[ yy_coeff] * point.y * point.y; |
| 34 | double x = coeffs[ x_coeff] * point.x; |
| 35 | double y = coeffs[ y_coeff] * point.y; |
| 36 | double c = coeffs[ c_coeff]; |
| 37 | double sum = xxx + xxy + xyy + yyy + xx + xy + yy + x + y + c; |
| 38 | return approximately_zero(sum); |
| 39 | } |