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 | 7 |
8 #include "SkRRect.h" | 8 #include "SkRRect.h" |
9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 | 10 |
11 /////////////////////////////////////////////////////////////////////////////// | 11 /////////////////////////////////////////////////////////////////////////////// |
12 | 12 |
13 void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) { | 13 void SkRRect::setRectXY(const SkRect& rect, SkScalar xRad, SkScalar yRad) { |
14 if (rect.isEmpty() || !rect.isFinite()) { | 14 if (rect.isEmpty() || !rect.isFinite()) { |
15 this->setEmpty(); | 15 this->setEmpty(); |
16 return; | 16 return; |
17 } | 17 } |
18 | 18 |
19 if (!SkScalarsAreFinite(xRad, yRad)) { | 19 if (!SkScalarsAreFinite(xRad, yRad)) { |
20 xRad = yRad = 0; // devolve into a simple rect | 20 xRad = yRad = 0; // devolve into a simple rect |
21 } | 21 } |
22 if (xRad <= 0 || yRad <= 0) { | 22 if (xRad <= 0 || yRad <= 0) { |
23 // all corners are square in this case | 23 // all corners are square in this case |
24 this->setRect(rect); | 24 this->setRect(rect); |
25 return; | 25 return; |
26 } | 26 } |
27 | 27 |
28 if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) { | 28 if (rect.width() < xRad+xRad || rect.height() < yRad+yRad) { |
29 SkScalar scale = SkMinScalar(rect.width() / (xRad + xRad), rect.height()
/ (yRad + yRad)); | 29 SkScalar scale = SkMinScalar(SkScalarDiv(rect.width(), xRad + xRad), |
| 30 SkScalarDiv(rect.height(), yRad + yRad)); |
30 SkASSERT(scale < SK_Scalar1); | 31 SkASSERT(scale < SK_Scalar1); |
31 xRad = SkScalarMul(xRad, scale); | 32 xRad = SkScalarMul(xRad, scale); |
32 yRad = SkScalarMul(yRad, scale); | 33 yRad = SkScalarMul(yRad, scale); |
33 } | 34 } |
34 | 35 |
35 fRect = rect; | 36 fRect = rect; |
36 for (int i = 0; i < 4; ++i) { | 37 for (int i = 0; i < 4; ++i) { |
37 fRadii[i].set(xRad, yRad); | 38 fRadii[i].set(xRad, yRad); |
38 } | 39 } |
39 fType = kSimple_Type; | 40 fType = kSimple_Type; |
(...skipping 18 matching lines...) Expand all Loading... |
58 return; | 59 return; |
59 } | 60 } |
60 | 61 |
61 leftRad = SkMaxScalar(leftRad, 0); | 62 leftRad = SkMaxScalar(leftRad, 0); |
62 topRad = SkMaxScalar(topRad, 0); | 63 topRad = SkMaxScalar(topRad, 0); |
63 rightRad = SkMaxScalar(rightRad, 0); | 64 rightRad = SkMaxScalar(rightRad, 0); |
64 bottomRad = SkMaxScalar(bottomRad, 0); | 65 bottomRad = SkMaxScalar(bottomRad, 0); |
65 | 66 |
66 SkScalar scale = SK_Scalar1; | 67 SkScalar scale = SK_Scalar1; |
67 if (leftRad + rightRad > rect.width()) { | 68 if (leftRad + rightRad > rect.width()) { |
68 scale = rect.width() / (leftRad + rightRad); | 69 scale = SkScalarDiv(rect.width(), leftRad + rightRad); |
69 } | 70 } |
70 if (topRad + bottomRad > rect.height()) { | 71 if (topRad + bottomRad > rect.height()) { |
71 scale = SkMinScalar(scale, rect.height() / (topRad + bottomRad)); | 72 scale = SkMinScalar(scale, SkScalarDiv(rect.height(), topRad + bottomRad
)); |
72 } | 73 } |
73 | 74 |
74 if (scale < SK_Scalar1) { | 75 if (scale < SK_Scalar1) { |
75 leftRad = SkScalarMul(leftRad, scale); | 76 leftRad = SkScalarMul(leftRad, scale); |
76 topRad = SkScalarMul(topRad, scale); | 77 topRad = SkScalarMul(topRad, scale); |
77 rightRad = SkScalarMul(rightRad, scale); | 78 rightRad = SkScalarMul(rightRad, scale); |
78 bottomRad = SkScalarMul(bottomRad, scale); | 79 bottomRad = SkScalarMul(bottomRad, scale); |
79 } | 80 } |
80 | 81 |
81 if (leftRad == rightRad && topRad == bottomRad) { | 82 if (leftRad == rightRad && topRad == bottomRad) { |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 } | 587 } |
587 | 588 |
588 for (int i = 0; i < 4; ++i) { | 589 for (int i = 0; i < 4; ++i) { |
589 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight
); | 590 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight
); |
590 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom
); | 591 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom
); |
591 } | 592 } |
592 } | 593 } |
593 #endif // SK_DEBUG | 594 #endif // SK_DEBUG |
594 | 595 |
595 /////////////////////////////////////////////////////////////////////////////// | 596 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |