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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 int num = SkDCubic::RootsReal(t4, t3, t2, t1, roots); | 64 int num = SkDCubic::RootsReal(t4, t3, t2, t1, roots); |
65 for (int i = 0; i < num; ++i) { | 65 for (int i = 0; i < num; ++i) { |
66 if (approximately_zero(roots[i])) { | 66 if (approximately_zero(roots[i])) { |
67 return num; | 67 return num; |
68 } | 68 } |
69 } | 69 } |
70 roots[num++] = 0; | 70 roots[num++] = 0; |
71 return num; | 71 return num; |
72 } | 72 } |
73 if (oneHint) { | 73 if (oneHint) { |
74 SkASSERT(approximately_zero(t4 + t3 + t2 + t1 + t0)); // 1 is one root | 74 SkASSERT(approximately_zero_double(t4 + t3 + t2 + t1 + t0)); // 1 is on
e root |
75 // note that -C == A + B + D + E | 75 // note that -C == A + B + D + E |
76 int num = SkDCubic::RootsReal(t4, t4 + t3, -(t1 + t0), -t0, roots); | 76 int num = SkDCubic::RootsReal(t4, t4 + t3, -(t1 + t0), -t0, roots); |
77 for (int i = 0; i < num; ++i) { | 77 for (int i = 0; i < num; ++i) { |
78 if (approximately_equal(roots[i], 1)) { | 78 if (approximately_equal(roots[i], 1)) { |
79 return num; | 79 return num; |
80 } | 80 } |
81 } | 81 } |
82 roots[num++] = 1; | 82 roots[num++] = 1; |
83 return num; | 83 return num; |
84 } | 84 } |
(...skipping 71 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 |