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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 SkRRect rr1; | 54 SkRRect rr1; |
55 rr1.setRect(rect); | 55 rr1.setRect(rect); |
56 | 56 |
57 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); | 57 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); |
58 REPORTER_ASSERT(reporter, rr1.rect() == rect); | 58 REPORTER_ASSERT(reporter, rr1.rect() == rect); |
59 | 59 |
60 for (int i = 0; i < 4; ++i) { | 60 for (int i = 0; i < 4; ++i) { |
61 REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i)); | 61 REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i)); |
62 } | 62 } |
| 63 SkRRect rr1_2; // construct the same RR using the most general set function |
| 64 SkVector rr1_2_radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; |
| 65 rr1_2.setRectRadii(rect, rr1_2_radii); |
| 66 REPORTER_ASSERT(reporter, rr1_2 == rr1 && rr1_2.getType() == rr1.getType()); |
| 67 SkRRect rr1_3; // construct the same RR using the nine patch set function |
| 68 rr1_3.setNinePatch(rect, 0, 0, 0, 0); |
| 69 REPORTER_ASSERT(reporter, rr1_3 == rr1 && rr1_3.getType() == rr1.getType()); |
63 | 70 |
64 //---- | 71 //---- |
65 SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) }; | 72 SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) }; |
66 SkRRect rr2; | 73 SkRRect rr2; |
67 rr2.setOval(rect); | 74 rr2.setOval(rect); |
68 | 75 |
69 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr2.type()); | 76 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr2.type()); |
70 REPORTER_ASSERT(reporter, rr2.rect() == rect); | 77 REPORTER_ASSERT(reporter, rr2.rect() == rect); |
71 | 78 |
72 for (int i = 0; i < 4; ++i) { | 79 for (int i = 0; i < 4; ++i) { |
73 REPORTER_ASSERT(reporter, | 80 REPORTER_ASSERT(reporter, |
74 rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(hal
fPoint)); | 81 rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(hal
fPoint)); |
75 } | 82 } |
| 83 SkRRect rr2_2; // construct the same RR using the most general set function |
| 84 SkVector rr2_2_radii[4] = { { halfPoint.fX, halfPoint.fY }, { halfPoint.fX,
halfPoint.fY }, |
| 85 { halfPoint.fX, halfPoint.fY }, { halfPoint.fX,
halfPoint.fY } }; |
| 86 rr2_2.setRectRadii(rect, rr2_2_radii); |
| 87 REPORTER_ASSERT(reporter, rr2_2 == rr2 && rr2_2.getType() == rr2.getType()); |
| 88 SkRRect rr2_3; // construct the same RR using the nine patch set function |
| 89 rr2_3.setNinePatch(rect, halfPoint.fX, halfPoint.fY, halfPoint.fX, halfPoint
.fY); |
| 90 REPORTER_ASSERT(reporter, rr2_3 == rr2 && rr2_3.getType() == rr2.getType()); |
76 | 91 |
77 //---- | 92 //---- |
78 SkPoint p = { 5, 5 }; | 93 SkPoint p = { 5, 5 }; |
79 SkRRect rr3; | 94 SkRRect rr3; |
80 rr3.setRectXY(rect, p.fX, p.fY); | 95 rr3.setRectXY(rect, p.fX, p.fY); |
81 | 96 |
82 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr3.type()); | 97 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr3.type()); |
83 REPORTER_ASSERT(reporter, rr3.rect() == rect); | 98 REPORTER_ASSERT(reporter, rr3.rect() == rect); |
84 | 99 |
85 for (int i = 0; i < 4; ++i) { | 100 for (int i = 0; i < 4; ++i) { |
86 REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i)); | 101 REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i)); |
87 } | 102 } |
| 103 SkRRect rr3_2; // construct the same RR using the most general set function |
| 104 SkVector rr3_2_radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } }; |
| 105 rr3_2.setRectRadii(rect, rr3_2_radii); |
| 106 REPORTER_ASSERT(reporter, rr3_2 == rr3 && rr3_2.getType() == rr3.getType()); |
| 107 SkRRect rr3_3; // construct the same RR using the nine patch set function |
| 108 rr3_3.setNinePatch(rect, 5, 5, 5, 5); |
| 109 REPORTER_ASSERT(reporter, rr3_3 == rr3 && rr3_3.getType() == rr3.getType()); |
88 | 110 |
89 //---- | 111 //---- |
90 SkPoint radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } }; | 112 SkRect ninePatchRadii = { 10, 9, 8, 7 }; |
91 | 113 |
92 SkRRect rr4; | 114 SkRRect rr4; |
93 rr4.setRectRadii(rect, radii); | 115 rr4.setNinePatch(rect, ninePatchRadii.fLeft, ninePatchRadii.fTop, ninePatchR
adii.fRight, |
| 116 ninePatchRadii.fBottom); |
94 | 117 |
95 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr4.type()); | 118 REPORTER_ASSERT(reporter, SkRRect::kNinePatch_Type == rr4.type()); |
96 REPORTER_ASSERT(reporter, rr4.rect() == rect); | 119 REPORTER_ASSERT(reporter, rr4.rect() == rect); |
97 | 120 |
| 121 SkPoint rquad[4]; |
| 122 ninePatchRadii.toQuad(rquad); |
98 for (int i = 0; i < 4; ++i) { | 123 for (int i = 0; i < 4; ++i) { |
99 REPORTER_ASSERT(reporter, radii[i] == rr4.radii((SkRRect::Corner) i)); | 124 REPORTER_ASSERT(reporter, rquad[i] == rr4.radii((SkRRect::Corner) i)); |
100 } | 125 } |
| 126 SkRRect rr4_2; // construct the same RR using the most general set function |
| 127 SkVector rr4_2_radii[4] = { { 10, 9 }, { 8, 9 }, {8, 7 }, { 10, 7 } }; |
| 128 rr4_2.setRectRadii(rect, rr4_2_radii); |
| 129 REPORTER_ASSERT(reporter, rr4_2 == rr4 && rr4_2.getType() == rr4.getType()); |
101 | 130 |
102 //---- | 131 //---- |
103 SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } }; | 132 SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } }; |
104 | 133 |
105 SkRRect rr5; | 134 SkRRect rr5; |
106 rr5.setRectRadii(rect, radii2); | 135 rr5.setRectRadii(rect, radii2); |
107 | 136 |
108 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr5.type()); | 137 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr5.type()); |
109 REPORTER_ASSERT(reporter, rr5.rect() == rect); | 138 REPORTER_ASSERT(reporter, rr5.rect() == rect); |
110 | 139 |
111 for (int i = 0; i < 4; ++i) { | 140 for (int i = 0; i < 4; ++i) { |
112 REPORTER_ASSERT(reporter, radii2[i] == rr5.radii((SkRRect::Corner) i)); | 141 REPORTER_ASSERT(reporter, radii2[i] == rr5.radii((SkRRect::Corner) i)); |
113 } | 142 } |
114 | 143 |
115 // Test out == & != | 144 // Test out == & != |
116 REPORTER_ASSERT(reporter, empty != rr3); | 145 REPORTER_ASSERT(reporter, empty != rr3); |
117 REPORTER_ASSERT(reporter, rr3 == rr4); | 146 REPORTER_ASSERT(reporter, rr3 != rr4); |
118 REPORTER_ASSERT(reporter, rr4 != rr5); | 147 REPORTER_ASSERT(reporter, rr4 != rr5); |
119 } | 148 } |
120 | 149 |
121 // Test out the cases when the RR degenerates to a rect | 150 // Test out the cases when the RR degenerates to a rect |
122 static void test_round_rect_rects(skiatest::Reporter* reporter) { | 151 static void test_round_rect_rects(skiatest::Reporter* reporter) { |
123 SkRect r; | 152 SkRect r; |
124 | 153 |
125 //---- | 154 //---- |
126 SkRRect empty; | 155 SkRRect empty; |
127 | 156 |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 DEF_TEST(RoundRect, reporter) { | 585 DEF_TEST(RoundRect, reporter) { |
557 test_round_rect_basic(reporter); | 586 test_round_rect_basic(reporter); |
558 test_round_rect_rects(reporter); | 587 test_round_rect_rects(reporter); |
559 test_round_rect_ovals(reporter); | 588 test_round_rect_ovals(reporter); |
560 test_round_rect_general(reporter); | 589 test_round_rect_general(reporter); |
561 test_round_rect_iffy_parameters(reporter); | 590 test_round_rect_iffy_parameters(reporter); |
562 test_inset(reporter); | 591 test_inset(reporter); |
563 test_round_rect_contains_rect(reporter); | 592 test_round_rect_contains_rect(reporter); |
564 test_round_rect_transform(reporter); | 593 test_round_rect_transform(reporter); |
565 } | 594 } |
OLD | NEW |