| OLD | NEW |
| 1 // from http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c | 1 // from http://tog.acm.org/resources/GraphicsGems/gems/Roots3And4.c |
| 2 /* | 2 /* |
| 3 * Roots3And4.c | 3 * Roots3And4.c |
| 4 * | 4 * |
| 5 * Utility functions to find cubic and quartic roots, | 5 * Utility functions to find cubic and quartic roots, |
| 6 * coefficients are passed like this: | 6 * coefficients are passed like this: |
| 7 * | 7 * |
| 8 * c[0] + c[1]*x + c[2]*x^2 + c[3]*x^3 + c[4]*x^4 = 0 | 8 * c[0] + c[1]*x + c[2]*x^2 + c[3]*x^3 + c[4]*x^4 = 0 |
| 9 * | 9 * |
| 10 * The functions return the number of non-complex roots and | 10 * The functions return the number of non-complex roots and |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 const double t0, const bool oneHint, double roots[4]) { | 33 const double t0, const bool oneHint, double roots[4]) { |
| 34 #ifdef SK_DEBUG | 34 #ifdef SK_DEBUG |
| 35 // create a string mathematica understands | 35 // create a string mathematica understands |
| 36 // GDB set print repe 15 # if repeated digits is a bother | 36 // GDB set print repe 15 # if repeated digits is a bother |
| 37 // set print elements 400 # if line doesn't fit | 37 // set print elements 400 # if line doesn't fit |
| 38 char str[1024]; | 38 char str[1024]; |
| 39 sk_bzero(str, sizeof(str)); | 39 sk_bzero(str, sizeof(str)); |
| 40 SK_SNPRINTF(str, sizeof(str), | 40 SK_SNPRINTF(str, sizeof(str), |
| 41 "Solve[%1.19g x^4 + %1.19g x^3 + %1.19g x^2 + %1.19g x + %1.19g == 0
, x]", | 41 "Solve[%1.19g x^4 + %1.19g x^3 + %1.19g x^2 + %1.19g x + %1.19g == 0
, x]", |
| 42 t4, t3, t2, t1, t0); | 42 t4, t3, t2, t1, t0); |
| 43 mathematica_ize(str, sizeof(str)); | 43 SkPathOpsDebug::MathematicaIze(str, sizeof(str)); |
| 44 #if ONE_OFF_DEBUG && ONE_OFF_DEBUG_MATHEMATICA | 44 #if ONE_OFF_DEBUG && ONE_OFF_DEBUG_MATHEMATICA |
| 45 SkDebugf("%s\n", str); | 45 SkDebugf("%s\n", str); |
| 46 #endif | 46 #endif |
| 47 #endif | 47 #endif |
| 48 if (approximately_zero_when_compared_to(t4, t0) // 0 is one root | 48 if (approximately_zero_when_compared_to(t4, t0) // 0 is one root |
| 49 && approximately_zero_when_compared_to(t4, t1) | 49 && approximately_zero_when_compared_to(t4, t1) |
| 50 && approximately_zero_when_compared_to(t4, t2)) { | 50 && approximately_zero_when_compared_to(t4, t2)) { |
| 51 if (approximately_zero_when_compared_to(t3, t0) | 51 if (approximately_zero_when_compared_to(t3, t0) |
| 52 && approximately_zero_when_compared_to(t3, t1) | 52 && approximately_zero_when_compared_to(t3, t1) |
| 53 && approximately_zero_when_compared_to(t3, t2)) { | 53 && approximately_zero_when_compared_to(t3, t2)) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (j < --num) { | 156 if (j < --num) { |
| 157 s[j] = s[num]; | 157 s[j] = s[num]; |
| 158 } | 158 } |
| 159 } else { | 159 } else { |
| 160 ++j; | 160 ++j; |
| 161 } | 161 } |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 return num; | 164 return num; |
| 165 } | 165 } |
| OLD | NEW |