aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops
diff options
context:
space:
mode:
authorGravatar Cary Clark <caryclark@skia.org>2018-03-13 10:39:30 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-13 15:01:43 +0000
commit65247e595d8e67ebc2857a8c3bb5ed53893b500d (patch)
tree11c2a141a511758ec20920b61d0cb98ff8d37ed1 /src/pathops
parent99b63400eb7734f5e46360c4a6b94914e1411586 (diff)
avoid divide by zero
R=kjlubick@google.com Bug: skia:7623 Change-Id: Ia9fb31201a39a4540d94f97e8d2f06eb290ab6e5 Reviewed-on: https://skia-review.googlesource.com/114082 Commit-Queue: Cary Clark <caryclark@skia.org> Commit-Queue: Cary Clark <caryclark@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
Diffstat (limited to 'src/pathops')
-rw-r--r--src/pathops/SkPathOpsQuad.cpp22
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;