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 "SkIntersections.h" | 7 #include "SkIntersections.h" |
8 #include "SkLineParameters.h" | 8 #include "SkLineParameters.h" |
9 #include "SkPathOpsCubic.h" | 9 #include "SkPathOpsCubic.h" |
10 #include "SkPathOpsCurve.h" | 10 #include "SkPathOpsCurve.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 Numeric Solutions (5.6) suggests to solve the quadratic by computing | 112 Numeric Solutions (5.6) suggests to solve the quadratic by computing |
113 Q = -1/2(B + sgn(B)Sqrt(B^2 - 4 A C)) | 113 Q = -1/2(B + sgn(B)Sqrt(B^2 - 4 A C)) |
114 and using the roots | 114 and using the roots |
115 t1 = Q / A | 115 t1 = Q / A |
116 t2 = C / Q | 116 t2 = C / Q |
117 */ | 117 */ |
118 // this does not discard real roots <= 0 or >= 1 | 118 // this does not discard real roots <= 0 or >= 1 |
119 int SkDQuad::RootsReal(const double A, const double B, const double C, double s[
2]) { | 119 int SkDQuad::RootsReal(const double A, const double B, const double C, double s[
2]) { |
120 const double p = B / (2 * A); | 120 const double p = B / (2 * A); |
121 const double q = C / A; | 121 const double q = C / A; |
122 if (approximately_zero(A) && (approximately_zero_inverse(p) || approximately
_zero_inverse(q))) { | 122 if (!A || (approximately_zero(A) && (approximately_zero_inverse(p) |
| 123 || approximately_zero_inverse(q)))) { |
123 if (approximately_zero(B)) { | 124 if (approximately_zero(B)) { |
124 s[0] = 0; | 125 s[0] = 0; |
125 return C == 0; | 126 return C == 0; |
126 } | 127 } |
127 s[0] = -C / B; | 128 s[0] = -C / B; |
128 return 1; | 129 return 1; |
129 } | 130 } |
130 /* normal form: x^2 + px + q = 0 */ | 131 /* normal form: x^2 + px + q = 0 */ |
131 const double p2 = p * p; | 132 const double p2 = p * p; |
132 if (!AlmostDequalUlps(p2, q) && p2 < q) { | 133 if (!AlmostDequalUlps(p2, q) && p2 < q) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 * c = C | 342 * c = C |
342 */ | 343 */ |
343 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { | 344 void SkDQuad::SetABC(const double* quad, double* a, double* b, double* c) { |
344 *a = quad[0]; // a = A | 345 *a = quad[0]; // a = A |
345 *b = 2 * quad[2]; // b = 2*B | 346 *b = 2 * quad[2]; // b = 2*B |
346 *c = quad[4]; // c = C | 347 *c = quad[4]; // c = C |
347 *b -= *c; // b = 2*B - C | 348 *b -= *c; // b = 2*B - C |
348 *a -= *b; // a = A - 2*B + C | 349 *a -= *b; // a = A - 2*B + C |
349 *b -= *c; // b = 2*B - 2*C | 350 *b -= *c; // b = 2*B - 2*C |
350 } | 351 } |
OLD | NEW |