Index: src/core/SkRRect.cpp |
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp |
index ad62e5bbae82947d337c977ba218e0e9ece53348..ca4fd561523f345b0f9b889c09ea5f44b13c628a 100644 |
--- a/src/core/SkRRect.cpp |
+++ b/src/core/SkRRect.cpp |
@@ -5,8 +5,10 @@ |
* found in the LICENSE file. |
*/ |
+#include <cmath> |
#include "SkRRect.h" |
#include "SkMatrix.h" |
+#include "SkScaleToSides.h" |
/////////////////////////////////////////////////////////////////////////////// |
@@ -109,28 +111,6 @@ void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad |
SkDEBUGCODE(this->validate();) |
} |
-/* |
- * TODO: clean this guy up and possibly add to SkScalar.h |
- */ |
-static inline SkScalar SkScalarDecULP(SkScalar value) { |
-#if SK_SCALAR_IS_FLOAT |
- return SkBits2Float(SkFloat2Bits(value) - 1); |
-#else |
- #error "need impl for doubles" |
-#endif |
-} |
- |
- /** |
- * We need all combinations of predicates to be true to have a "safe" radius value. |
- */ |
-static SkScalar clamp_radius_check_predicates(SkScalar rad, SkScalar min, SkScalar max) { |
- SkASSERT(min < max); |
- if (rad > max - min || min + rad > max || max - rad < min) { |
- rad = SkScalarDecULP(rad); |
- } |
- return rad; |
-} |
- |
// These parameters intentionally double. Apropos crbug.com/463920, if one of the |
// radii is huge while the other is small, single precision math can completely |
// miss the fact that a scale is required. |
@@ -190,29 +170,21 @@ void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) { |
// If f < 1, then all corner radii are reduced by multiplying them by f." |
double scale = 1.0; |
- scale = compute_min_scale(fRadii[0].fX, fRadii[1].fX, fRect.width(), scale); |
- scale = compute_min_scale(fRadii[1].fY, fRadii[2].fY, fRect.height(), scale); |
- scale = compute_min_scale(fRadii[2].fX, fRadii[3].fX, fRect.width(), scale); |
- scale = compute_min_scale(fRadii[3].fY, fRadii[0].fY, fRect.height(), scale); |
+ // The sides of the rectangle may be larger than a float. |
+ double width = (double)fRect.fRight - (double)fRect.fLeft; |
+ double height = (double)fRect.fBottom - (double)fRect.fTop; |
+ scale = compute_min_scale(fRadii[0].fX, fRadii[1].fX, width, scale); |
+ scale = compute_min_scale(fRadii[1].fY, fRadii[2].fY, height, scale); |
+ scale = compute_min_scale(fRadii[2].fX, fRadii[3].fX, width, scale); |
+ scale = compute_min_scale(fRadii[3].fY, fRadii[0].fY, height, scale); |
if (scale < 1.0) { |
- for (int i = 0; i < 4; ++i) { |
- fRadii[i].fX *= scale; |
- fRadii[i].fY *= scale; |
- } |
+ ScaleToSides::AdjustRadii(width, scale, &fRadii[0].fX, &fRadii[1].fX); |
+ ScaleToSides::AdjustRadii(height, scale, &fRadii[1].fY, &fRadii[2].fY); |
+ ScaleToSides::AdjustRadii(width, scale, &fRadii[2].fX, &fRadii[3].fX); |
+ ScaleToSides::AdjustRadii(height, scale, &fRadii[3].fY, &fRadii[0].fY); |
} |
- // https://bug.skia.org/3239 -- its possible that we can hit the following inconsistency: |
- // rad == bounds.bottom - bounds.top |
- // bounds.bottom - radius < bounds.top |
- // YIKES |
- // We need to detect and "fix" this now, otherwise we can have the following wackiness: |
- // path.addRRect(rrect); |
- // rrect.rect() != path.getBounds() |
- for (int i = 0; i < 4; ++i) { |
- fRadii[i].fX = clamp_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight); |
- fRadii[i].fY = clamp_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom); |
- } |
// At this point we're either oval, simple, or complex (not empty or rect). |
this->computeType(); |