Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: src/core/SkRRect.cpp

Issue 1373293002: Handle inverted rects in SkRRect creation methods (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed SK_ARRAY_COUNT error Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkRRect.h ('k') | tests/RoundRectTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRRect.cpp
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index ef811215f4436a0e69793bac52fed1f2f4c8eaa8..2f576fa95a1fc32cec8098339c73e98a14600e27 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -11,7 +11,10 @@
///////////////////////////////////////////////////////////////////////////////
void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
- if (rect.isEmpty() || !rect.isFinite()) {
+ fRect = rect;
+ fRect.sort();
+
+ if (fRect.isEmpty() || !fRect.isFinite()) {
this->setEmpty();
return;
}
@@ -25,14 +28,13 @@ void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
return;
}
- if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) {
- SkScalar scale = SkMinScalar(rect.width() / (xRad + xRad), rect.height() / (yRad + yRad));
+ if (fRect.width() < xRad+xRad || fRect.height() < yRad+yRad) {
+ SkScalar scale = SkMinScalar(fRect.width() / (xRad + xRad), fRect.height() / (yRad + yRad));
SkASSERT(scale < SK_Scalar1);
xRad = SkScalarMul(xRad, scale);
yRad = SkScalarMul(yRad, scale);
}
- fRect = rect;
for (int i = 0; i < 4; ++i) {
fRadii[i].set(xRad, yRad);
}
@@ -47,7 +49,10 @@ void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) {
void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad,
SkScalar rightRad, SkScalar bottomRad) {
- if (rect.isEmpty() || !rect.isFinite()) {
+ fRect = rect;
+ fRect.sort();
+
+ if (fRect.isEmpty() || !fRect.isFinite()) {
this->setEmpty();
return;
}
@@ -64,11 +69,11 @@ void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad
bottomRad = SkMaxScalar(bottomRad, 0);
SkScalar scale = SK_Scalar1;
- if (leftRad + rightRad > rect.width()) {
- scale = rect.width() / (leftRad + rightRad);
+ if (leftRad + rightRad > fRect.width()) {
+ scale = fRect.width() / (leftRad + rightRad);
}
- if (topRad + bottomRad > rect.height()) {
- scale = SkMinScalar(scale, rect.height() / (topRad + bottomRad));
+ if (topRad + bottomRad > fRect.height()) {
+ scale = SkMinScalar(scale, fRect.height() / (topRad + bottomRad));
}
if (scale < SK_Scalar1) {
@@ -79,7 +84,7 @@ void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad
}
if (leftRad == rightRad && topRad == bottomRad) {
- if (leftRad >= SkScalarHalf(rect.width()) && topRad >= SkScalarHalf(rect.height())) {
+ if (leftRad >= SkScalarHalf(fRect.width()) && topRad >= SkScalarHalf(fRect.height())) {
fType = kOval_Type;
} else if (0 == leftRad || 0 == topRad) {
// If the left and (by equality check above) right radii are zero then it is a rect.
@@ -96,7 +101,6 @@ void SkRRect::setNinePatch(const SkRect& rect, SkScalar leftRad, SkScalar topRad
fType = kNinePatch_Type;
}
- fRect = rect;
fRadii[kUpperLeft_Corner].set(leftRad, topRad);
fRadii[kUpperRight_Corner].set(rightRad, topRad);
fRadii[kLowerRight_Corner].set(rightRad, bottomRad);
@@ -138,7 +142,10 @@ static double compute_min_scale(double rad1, double rad2, double limit, double c
}
void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
- if (rect.isEmpty() || !rect.isFinite()) {
+ fRect = rect;
+ fRect.sort();
+
+ if (fRect.isEmpty() || !fRect.isFinite()) {
this->setEmpty();
return;
}
@@ -148,7 +155,6 @@ void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
return;
}
- fRect = rect;
memcpy(fRadii, radii, sizeof(fRadii));
bool allCornersSquare = true;
@@ -184,10 +190,10 @@ 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, rect.width(), scale);
- scale = compute_min_scale(fRadii[1].fY, fRadii[2].fY, rect.height(), scale);
- scale = compute_min_scale(fRadii[2].fX, fRadii[3].fX, rect.width(), scale);
- scale = compute_min_scale(fRadii[3].fY, fRadii[0].fY, rect.height(), scale);
+ 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);
if (scale < 1.0) {
for (int i = 0; i < 4; ++i) {
@@ -204,8 +210,8 @@ void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
// path.addRRect(rrect);
// rrect.rect() != path.getBounds()
for (int i = 0; i < 4; ++i) {
- fRadii[i].fX = clamp_radius_check_predicates(fRadii[i].fX, rect.fLeft, rect.fRight);
- fRadii[i].fY = clamp_radius_check_predicates(fRadii[i].fY, rect.fTop, rect.fBottom);
+ 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();
« no previous file with comments | « include/core/SkRRect.h ('k') | tests/RoundRectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698