diff options
author | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-25 18:57:23 +0000 |
---|---|---|
committer | caryclark@google.com <caryclark@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-01-25 18:57:23 +0000 |
commit | 27accef223a27fba437f5e825d99edbae20a045b (patch) | |
tree | bba808edd5117406ec3d17f08baebdbbd4338a1a /experimental/Intersection/CubicParameterization_TestUtility.cpp | |
parent | 76bd2540b55f31c8e72adb2fa72a88d7f4ba5374 (diff) |
Intersection work in progress
Review URL: https://codereview.appspot.com/5576043
git-svn-id: http://skia.googlecode.com/svn/trunk@3087 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/Intersection/CubicParameterization_TestUtility.cpp')
-rw-r--r-- | experimental/Intersection/CubicParameterization_TestUtility.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/experimental/Intersection/CubicParameterization_TestUtility.cpp b/experimental/Intersection/CubicParameterization_TestUtility.cpp new file mode 100644 index 0000000000..2423a7cd5e --- /dev/null +++ b/experimental/Intersection/CubicParameterization_TestUtility.cpp @@ -0,0 +1,39 @@ +// included by CubicParameterization.cpp +// accesses internal functions to validate parameterized coefficients + +static void parameter_coeffs(const Cubic& cubic, double coeffs[coeff_count]) { + double ax, bx, cx, dx; + if (try_alt) + alt_set_abcd(&cubic[0].x, ax, bx, cx, dx); + else + set_abcd(&cubic[0].x, ax, bx, cx, dx); + double ay, by, cy, dy; + if (try_alt) + alt_set_abcd(&cubic[0].y, ay, by, cy, dy); + else + set_abcd(&cubic[0].y, ay, by, cy, dy); + calc_ABCD(ax, ay, coeffs); + if (!try_alt) calc_bc(dx, bx, cx); + if (!try_alt) calc_bc(dy, by, cy); + for (int index = xx_coeff; index < coeff_count; ++index) { + int procIndex = index - xx_coeff; + coeffs[index] = (*calc_proc[procIndex])(ax, bx, cx, dx, ay, by, cy, dy); + } +} + +bool point_on_parameterized_curve(const Cubic& cubic, const _Point& point) { + double coeffs[coeff_count]; + parameter_coeffs(cubic, coeffs); + double xxx = coeffs[xxx_coeff] * point.x * point.x * point.x; + double xxy = coeffs[xxy_coeff] * point.x * point.x * point.y; + double xyy = coeffs[xyy_coeff] * point.x * point.y * point.y; + double yyy = coeffs[yyy_coeff] * point.y * point.y * point.y; + double xx = coeffs[ xx_coeff] * point.x * point.x; + double xy = coeffs[ xy_coeff] * point.x * point.y; + double yy = coeffs[ yy_coeff] * point.y * point.y; + double x = coeffs[ x_coeff] * point.x; + double y = coeffs[ y_coeff] * point.y; + double c = coeffs[ c_coeff]; + double sum = xxx + xxy + xyy + yyy + xx + xy + yy + x + y + c; + return approximately_zero(sum); +} |