diff options
Diffstat (limited to 'src/pathops')
-rw-r--r-- | src/pathops/SkPathOpsQuad.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/pathops/SkPathOpsQuad.cpp b/src/pathops/SkPathOpsQuad.cpp index f410ea3737..9a104bfe2b 100644 --- a/src/pathops/SkPathOpsQuad.cpp +++ b/src/pathops/SkPathOpsQuad.cpp @@ -141,6 +141,15 @@ int SkDQuad::RootsValidT(double A, double B, double C, double t[2]) { return foundRoots; } +static int handle_zero(const double B, const double C, double s[2]) { + if (approximately_zero(B)) { + s[0] = 0; + return C == 0; + } + s[0] = -C / B; + return 1; +} + /* Numeric Solutions (5.6) suggests to solve the quadratic by computing Q = -1/2(B + sgn(B)Sqrt(B^2 - 4 A C)) @@ -150,16 +159,13 @@ and using the roots */ // this does not discard real roots <= 0 or >= 1 int SkDQuad::RootsReal(const double A, const double B, const double C, double s[2]) { + if (!A) { + return handle_zero(B, C, s); + } const double p = B / (2 * A); const double q = C / A; - if (!A || (approximately_zero(A) && (approximately_zero_inverse(p) - || approximately_zero_inverse(q)))) { - if (approximately_zero(B)) { - s[0] = 0; - return C == 0; - } - s[0] = -C / B; - return 1; + if (approximately_zero(A) && (approximately_zero_inverse(p) || approximately_zero_inverse(q))) { + return handle_zero(B, C, s); } /* normal form: x^2 + px + q = 0 */ const double p2 = p * p; |