| 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 "SkGeometry.h" | 7 #include "SkGeometry.h" |
| 8 #include "SkLineParameters.h" | 8 #include "SkLineParameters.h" |
| 9 #include "SkPathOpsConic.h" | 9 #include "SkPathOpsConic.h" |
| 10 #include "SkPathOpsCubic.h" | 10 #include "SkPathOpsCubic.h" |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 double a2 = a * a; | 412 double a2 = a * a; |
| 413 double Q = (a2 - b * 3) / 9; | 413 double Q = (a2 - b * 3) / 9; |
| 414 double R = (2 * a2 * a - 9 * a * b + 27 * c) / 54; | 414 double R = (2 * a2 * a - 9 * a * b + 27 * c) / 54; |
| 415 double R2 = R * R; | 415 double R2 = R * R; |
| 416 double Q3 = Q * Q * Q; | 416 double Q3 = Q * Q * Q; |
| 417 double R2MinusQ3 = R2 - Q3; | 417 double R2MinusQ3 = R2 - Q3; |
| 418 double adiv3 = a / 3; | 418 double adiv3 = a / 3; |
| 419 double r; | 419 double r; |
| 420 double* roots = s; | 420 double* roots = s; |
| 421 if (R2MinusQ3 < 0) { // we have 3 real roots | 421 if (R2MinusQ3 < 0) { // we have 3 real roots |
| 422 double theta = acos(R / sqrt(Q3)); | 422 // the divide/root can, due to finite precisions, be slightly outside of
-1...1 |
| 423 double theta = acos(SkTPin(R / sqrt(Q3), -1., 1.)); |
| 423 double neg2RootQ = -2 * sqrt(Q); | 424 double neg2RootQ = -2 * sqrt(Q); |
| 424 | 425 |
| 425 r = neg2RootQ * cos(theta / 3) - adiv3; | 426 r = neg2RootQ * cos(theta / 3) - adiv3; |
| 426 *roots++ = r; | 427 *roots++ = r; |
| 427 | 428 |
| 428 r = neg2RootQ * cos((theta + 2 * PI) / 3) - adiv3; | 429 r = neg2RootQ * cos((theta + 2 * PI) / 3) - adiv3; |
| 429 if (!AlmostDequalUlps(s[0], r)) { | 430 if (!AlmostDequalUlps(s[0], r)) { |
| 430 *roots++ = r; | 431 *roots++ = r; |
| 431 } | 432 } |
| 432 r = neg2RootQ * cos((theta - 2 * PI) / 3) - adiv3; | 433 r = neg2RootQ * cos((theta - 2 * PI) / 3) - adiv3; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 for (int index = 0; index < roots; ++index) { | 690 for (int index = 0; index < roots; ++index) { |
| 690 double t = startT + (endT - startT) * extremeTs[index]; | 691 double t = startT + (endT - startT) * extremeTs[index]; |
| 691 SkDPoint mid = dCurve.ptAtT(t); | 692 SkDPoint mid = dCurve.ptAtT(t); |
| 692 if (topPt->fY > mid.fY || (topPt->fY == mid.fY && topPt->fX > mid.fX)) { | 693 if (topPt->fY > mid.fY || (topPt->fY == mid.fY && topPt->fX > mid.fX)) { |
| 693 topT = t; | 694 topT = t; |
| 694 *topPt = mid; | 695 *topPt = mid; |
| 695 } | 696 } |
| 696 } | 697 } |
| 697 return topT; | 698 return topT; |
| 698 } | 699 } |
| OLD | NEW |