| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 #include "CubicUtilities.h" | 7 #include "CubicUtilities.h" |
| 8 #include "Extrema.h" | 8 #include "Extrema.h" |
| 9 #include "LineUtilities.h" | 9 #include "LineUtilities.h" |
| 10 #include "QuadraticUtilities.h" | 10 #include "QuadraticUtilities.h" |
| 11 | 11 |
| 12 const int gPrecisionUnit = 256; // FIXME: arbitrary -- should try different valu
es in test framework | 12 const int gPrecisionUnit = 256; // FIXME: arbitrary -- should try different valu
es in test framework |
| 13 | 13 |
| 14 // FIXME: cache keep the bounds and/or precision with the caller? | 14 // FIXME: cache keep the bounds and/or precision with the caller? |
| 15 double calcPrecision(const Cubic& cubic) { | 15 double calcPrecision(const Cubic& cubic) { |
| 16 _Rect dRect; | 16 _Rect dRect; |
| 17 dRect.setBounds(cubic); // OPTIMIZATION: just use setRawBounds ? | 17 dRect.setBounds(cubic); // OPTIMIZATION: just use setRawBounds ? |
| 18 double width = dRect.right - dRect.left; | 18 double width = dRect.right - dRect.left; |
| 19 double height = dRect.bottom - dRect.top; | 19 double height = dRect.bottom - dRect.top; |
| 20 return (width > height ? width : height) / gPrecisionUnit; | 20 return (width > height ? width : height) / gPrecisionUnit; |
| 21 } | 21 } |
| 22 | 22 |
| 23 #if SK_DEBUG | 23 #ifdef SK_DEBUG |
| 24 double calcPrecision(const Cubic& cubic, double t, double scale) { | 24 double calcPrecision(const Cubic& cubic, double t, double scale) { |
| 25 Cubic part; | 25 Cubic part; |
| 26 sub_divide(cubic, SkTMax(0., t - scale), SkTMin(1., t + scale), part); | 26 sub_divide(cubic, SkTMax(0., t - scale), SkTMin(1., t + scale), part); |
| 27 return calcPrecision(part); | 27 return calcPrecision(part); |
| 28 } | 28 } |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 bool clockwise(const Cubic& c) { | 31 bool clockwise(const Cubic& c) { |
| 32 double sum = (c[0].x - c[3].x) * (c[0].y + c[3].y); | 32 double sum = (c[0].x - c[3].x) * (c[0].y + c[3].y); |
| 33 for (int idx = 0; idx < 3; ++idx){ | 33 for (int idx = 0; idx < 3; ++idx){ |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 return (int)(roots - t); | 159 return (int)(roots - t); |
| 160 #else | 160 #else |
| 161 double s[3]; | 161 double s[3]; |
| 162 int realRoots = cubicRootsReal(A, B, C, D, s); | 162 int realRoots = cubicRootsReal(A, B, C, D, s); |
| 163 int foundRoots = add_valid_ts(s, realRoots, t); | 163 int foundRoots = add_valid_ts(s, realRoots, t); |
| 164 return foundRoots; | 164 return foundRoots; |
| 165 #endif | 165 #endif |
| 166 } | 166 } |
| 167 | 167 |
| 168 int cubicRootsReal(double A, double B, double C, double D, double s[3]) { | 168 int cubicRootsReal(double A, double B, double C, double D, double s[3]) { |
| 169 #if SK_DEBUG | 169 #ifdef SK_DEBUG |
| 170 // create a string mathematica understands | 170 // create a string mathematica understands |
| 171 // GDB set print repe 15 # if repeated digits is a bother | 171 // GDB set print repe 15 # if repeated digits is a bother |
| 172 // set print elements 400 # if line doesn't fit | 172 // set print elements 400 # if line doesn't fit |
| 173 char str[1024]; | 173 char str[1024]; |
| 174 bzero(str, sizeof(str)); | 174 bzero(str, sizeof(str)); |
| 175 sprintf(str, "Solve[%1.19g x^3 + %1.19g x^2 + %1.19g x + %1.19g == 0, x]", A
, B, C, D); | 175 sprintf(str, "Solve[%1.19g x^3 + %1.19g x^2 + %1.19g x + %1.19g == 0, x]", A
, B, C, D); |
| 176 mathematica_ize(str, sizeof(str)); | 176 mathematica_ize(str, sizeof(str)); |
| 177 #if ONE_OFF_DEBUG && ONE_OFF_DEBUG_MATHEMATICA | 177 #if ONE_OFF_DEBUG && ONE_OFF_DEBUG_MATHEMATICA |
| 178 SkDebugf("%s\n", str); | 178 SkDebugf("%s\n", str); |
| 179 #endif | 179 #endif |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 double one_t2 = one_t * one_t; | 415 double one_t2 = one_t * one_t; |
| 416 double a = one_t2 * one_t; | 416 double a = one_t2 * one_t; |
| 417 double b = 3 * one_t2 * t; | 417 double b = 3 * one_t2 * t; |
| 418 double t2 = t * t; | 418 double t2 = t * t; |
| 419 double c = 3 * one_t * t2; | 419 double c = 3 * one_t * t2; |
| 420 double d = t2 * t; | 420 double d = t2 * t; |
| 421 _Point result = {a * cubic[0].x + b * cubic[1].x + c * cubic[2].x + d * cubi
c[3].x, | 421 _Point result = {a * cubic[0].x + b * cubic[1].x + c * cubic[2].x + d * cubi
c[3].x, |
| 422 a * cubic[0].y + b * cubic[1].y + c * cubic[2].y + d * cubic[3].y}; | 422 a * cubic[0].y + b * cubic[1].y + c * cubic[2].y + d * cubic[3].y}; |
| 423 return result; | 423 return result; |
| 424 } | 424 } |
| OLD | NEW |