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

Side by Side Diff: tests/RoundRectTest.cpp

Issue 51953003: remove contains(x,y) for rects and rrects ... not well defined, and unused (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« src/core/SkPath.cpp ('K') | « src/core/SkRRect.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "Test.h" 8 #include "Test.h"
9 #include "SkRRect.h" 9 #include "SkRRect.h"
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 // Test out == & != 114 // Test out == & !=
115 REPORTER_ASSERT(reporter, empty != rr3); 115 REPORTER_ASSERT(reporter, empty != rr3);
116 REPORTER_ASSERT(reporter, rr3 == rr4); 116 REPORTER_ASSERT(reporter, rr3 == rr4);
117 REPORTER_ASSERT(reporter, rr4 != rr5); 117 REPORTER_ASSERT(reporter, rr4 != rr5);
118 } 118 }
119 119
120 // Test out the cases when the RR degenerates to a rect 120 // Test out the cases when the RR degenerates to a rect
121 static void test_round_rect_rects(skiatest::Reporter* reporter) { 121 static void test_round_rect_rects(skiatest::Reporter* reporter) {
122 SkRect r; 122 SkRect r;
123 static const SkPoint pts[] = {
124 // Upper Left
125 { -SK_Scalar1, -SK_Scalar1 }, // out
126 { SK_Scalar1, SK_Scalar1 }, // in
127 // Upper Right
128 { SkIntToScalar(101), -SK_Scalar1}, // out
129 { SkIntToScalar(99), SK_Scalar1 }, // in
130 // Lower Right
131 { SkIntToScalar(101), SkIntToScalar(101) }, // out
132 { SkIntToScalar(99), SkIntToScalar(99) }, // in
133 // Lower Left
134 { -SK_Scalar1, SkIntToScalar(101) }, // out
135 { SK_Scalar1, SkIntToScalar(99) }, // in
136 // Middle
137 { SkIntToScalar(50), SkIntToScalar(50) } // in
138 };
139 static const bool isIn[] = { false, true, false, true, false, true, false, t rue, true };
140
141 SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn));
142 123
143 //---- 124 //----
144 SkRRect empty; 125 SkRRect empty;
145 126
146 empty.setEmpty(); 127 empty.setEmpty();
147 128
148 REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == empty.type()); 129 REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == empty.type());
149 r = empty.rect(); 130 r = empty.rect();
150 REPORTER_ASSERT(reporter, 0 == r.fLeft && 0 == r.fTop && 0 == r.fRight && 0 == r.fBottom); 131 REPORTER_ASSERT(reporter, 0 == r.fLeft && 0 == r.fTop && 0 == r.fRight && 0 == r.fBottom);
151 132
152 //---- 133 //----
153 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); 134 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
154 SkRRect rr1; 135 SkRRect rr1;
155 rr1.setRectXY(rect, 0, 0); 136 rr1.setRectXY(rect, 0, 0);
156 137
157 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); 138 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type());
158 r = rr1.rect(); 139 r = rr1.rect();
159 REPORTER_ASSERT(reporter, rect == r); 140 REPORTER_ASSERT(reporter, rect == r);
160 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
161 REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)) ;
162 }
163 141
164 //---- 142 //----
165 SkPoint radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; 143 SkPoint radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } };
166 144
167 SkRRect rr2; 145 SkRRect rr2;
168 rr2.setRectRadii(rect, radii); 146 rr2.setRectRadii(rect, radii);
169 147
170 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type()); 148 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type());
171 r = rr2.rect(); 149 r = rr2.rect();
172 REPORTER_ASSERT(reporter, rect == r); 150 REPORTER_ASSERT(reporter, rect == r);
173 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
174 REPORTER_ASSERT(reporter, isIn[i] == rr2.contains(pts[i].fX, pts[i].fY)) ;
175 }
176 151
177 //---- 152 //----
178 SkPoint radii2[4] = { { 0, 0 }, { 20, 20 }, { 50, 50 }, { 20, 50 } }; 153 SkPoint radii2[4] = { { 0, 0 }, { 20, 20 }, { 50, 50 }, { 20, 50 } };
179 154
180 SkRRect rr3; 155 SkRRect rr3;
181 rr3.setRectRadii(rect, radii2); 156 rr3.setRectRadii(rect, radii2);
182 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr3.type()); 157 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr3.type());
183 } 158 }
184 159
185 // Test out the cases when the RR degenerates to an oval 160 // Test out the cases when the RR degenerates to an oval
186 static void test_round_rect_ovals(skiatest::Reporter* reporter) { 161 static void test_round_rect_ovals(skiatest::Reporter* reporter) {
187 static const SkScalar kEps = 0.1f;
188 static const SkScalar kWidthTol = SkScalarHalf(kWidth) * (SK_Scalar1 - SK_Sc alarRoot2Over2);
189 static const SkScalar kHeightTol = SkScalarHalf(kHeight) * (SK_Scalar1 - SK_ ScalarRoot2Over2);
190 static const SkPoint pts[] = {
191 // Upper Left
192 { kWidthTol - kEps, kHeightTol - kEps }, // out
193 { kWidthTol + kEps, kHeightTol + kEps }, // in
194 // Upper Right
195 { kWidth + kEps - kWidthTol, kHeightTol - kEps }, // out
196 { kWidth - kEps - kWidthTol, kHeightTol + kEps }, // in
197 // Lower Right
198 { kWidth + kEps - kWidthTol, kHeight + kEps - kHeightTol }, // out
199 { kWidth - kEps - kWidthTol, kHeight - kEps - kHeightTol }, // in
200 // Lower Left
201 { kWidthTol - kEps, kHeight + kEps - kHeightTol }, //out
202 { kWidthTol + kEps, kHeight - kEps - kHeightTol }, // in
203 // Middle
204 { SkIntToScalar(50), SkIntToScalar(50) } // in
205 };
206 static const bool isIn[] = { false, true, false, true, false, true, false, t rue, true };
207
208 SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn));
209
210 //---- 162 //----
211 SkRect oval; 163 SkRect oval;
212 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); 164 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
213 SkRRect rr1; 165 SkRRect rr1;
214 rr1.setRectXY(rect, SkScalarHalf(kWidth), SkScalarHalf(kHeight)); 166 rr1.setRectXY(rect, SkScalarHalf(kWidth), SkScalarHalf(kHeight));
215 167
216 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr1.type()); 168 REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr1.type());
217 oval = rr1.rect(); 169 oval = rr1.rect();
218 REPORTER_ASSERT(reporter, oval == rect); 170 REPORTER_ASSERT(reporter, oval == rect);
219 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
220 REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)) ;
221 }
222 } 171 }
223 172
224 // Test out the non-degenerate RR cases 173 // Test out the non-degenerate RR cases
225 static void test_round_rect_general(skiatest::Reporter* reporter) { 174 static void test_round_rect_general(skiatest::Reporter* reporter) {
226 static const SkScalar kEps = 0.1f;
227 static const SkScalar kDist20 = 20 * (SK_Scalar1 - SK_ScalarRoot2Over2);
228 static const SkPoint pts[] = {
229 // Upper Left
230 { kDist20 - kEps, kDist20 - kEps }, // out
231 { kDist20 + kEps, kDist20 + kEps }, // in
232 // Upper Right
233 { kWidth + kEps - kDist20, kDist20 - kEps }, // out
234 { kWidth - kEps - kDist20, kDist20 + kEps }, // in
235 // Lower Right
236 { kWidth + kEps - kDist20, kHeight + kEps - kDist20 }, // out
237 { kWidth - kEps - kDist20, kHeight - kEps - kDist20 }, // in
238 // Lower Left
239 { kDist20 - kEps, kHeight + kEps - kDist20 }, //out
240 { kDist20 + kEps, kHeight - kEps - kDist20 }, // in
241 // Middle
242 { SkIntToScalar(50), SkIntToScalar(50) } // in
243 };
244 static const bool isIn[] = { false, true, false, true, false, true, false, t rue, true };
245
246 SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn));
247
248 //---- 175 //----
249 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); 176 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
250 SkRRect rr1; 177 SkRRect rr1;
251 rr1.setRectXY(rect, 20, 20); 178 rr1.setRectXY(rect, 20, 20);
252 179
253 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr1.type()); 180 REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr1.type());
254 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
255 REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)) ;
256 }
257 181
258 //---- 182 //----
259 static const SkScalar kDist50 = 50*(SK_Scalar1 - SK_ScalarRoot2Over2);
260 static const SkPoint pts2[] = {
261 // Upper Left
262 { -SK_Scalar1, -SK_Scalar1 }, // out
263 { SK_Scalar1, SK_Scalar1 }, // in
264 // Upper Right
265 { kWidth + kEps - kDist20, kDist20 - kEps }, // out
266 { kWidth - kEps - kDist20, kDist20 + kEps }, // in
267 // Lower Right
268 { kWidth + kEps - kDist50, kHeight + kEps - kDist50 }, // out
269 { kWidth - kEps - kDist50, kHeight - kEps - kDist50 }, // in
270 // Lower Left
271 { kDist20 - kEps, kHeight + kEps - kDist50 }, // out
272 { kDist20 + kEps, kHeight - kEps - kDist50 }, // in
273 // Middle
274 { SkIntToScalar(50), SkIntToScalar(50) } // in
275 };
276
277 SkASSERT(SK_ARRAY_COUNT(pts2) == SK_ARRAY_COUNT(isIn));
278
279 SkPoint radii[4] = { { 0, 0 }, { 20, 20 }, { 50, 50 }, { 20, 50 } }; 183 SkPoint radii[4] = { { 0, 0 }, { 20, 20 }, { 50, 50 }, { 20, 50 } };
280 184
281 SkRRect rr2; 185 SkRRect rr2;
282 rr2.setRectRadii(rect, radii); 186 rr2.setRectRadii(rect, radii);
283 187
284 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr2.type()); 188 REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr2.type());
285 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
286 REPORTER_ASSERT(reporter, isIn[i] == rr2.contains(pts2[i].fX, pts2[i].fY ));
287 }
288 } 189 }
289 190
290 // Test out questionable-parameter handling 191 // Test out questionable-parameter handling
291 static void test_round_rect_iffy_parameters(skiatest::Reporter* reporter) { 192 static void test_round_rect_iffy_parameters(skiatest::Reporter* reporter) {
292 193
293 // When the radii exceed the base rect they are proportionally scaled down 194 // When the radii exceed the base rect they are proportionally scaled down
294 // to fit 195 // to fit
295 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); 196 SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
296 SkPoint radii[4] = { { 50, 100 }, { 100, 50 }, { 50, 100 }, { 100, 50 } }; 197 SkPoint radii[4] = { { 50, 100 }, { 100, 50 }, { 50, 100 }, { 100, 50 } };
297 198
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 test_round_rect_rects(reporter); 357 test_round_rect_rects(reporter);
457 test_round_rect_ovals(reporter); 358 test_round_rect_ovals(reporter);
458 test_round_rect_general(reporter); 359 test_round_rect_general(reporter);
459 test_round_rect_iffy_parameters(reporter); 360 test_round_rect_iffy_parameters(reporter);
460 test_inset(reporter); 361 test_inset(reporter);
461 test_round_rect_contains_rect(reporter); 362 test_round_rect_contains_rect(reporter);
462 } 363 }
463 364
464 #include "TestClassDef.h" 365 #include "TestClassDef.h"
465 DEFINE_TESTCLASS("RoundRect", TestRoundRectClass, TestRoundRect) 366 DEFINE_TESTCLASS("RoundRect", TestRoundRectClass, TestRoundRect)
OLDNEW
« src/core/SkPath.cpp ('K') | « src/core/SkRRect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698