robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "Test.h" |
| 9 | #include "SkRRect.h" |
| 10 | |
| 11 | static const SkScalar kWidth = 100.0f; |
| 12 | static const SkScalar kHeight = 100.0f; |
| 13 | |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 14 | static void test_inset(skiatest::Reporter* reporter) { |
| 15 | SkRRect rr, rr2; |
| 16 | SkRect r = { 0, 0, 100, 100 }; |
| 17 | |
| 18 | rr.setRect(r); |
| 19 | rr.inset(-20, -20, &rr2); |
| 20 | REPORTER_ASSERT(reporter, rr2.isRect()); |
| 21 | |
| 22 | rr.inset(20, 20, &rr2); |
| 23 | REPORTER_ASSERT(reporter, rr2.isRect()); |
skia.committer@gmail.com | 1a60dab | 2012-12-24 02:01:25 +0000 | [diff] [blame] | 24 | |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 25 | rr.inset(r.width()/2, r.height()/2, &rr2); |
| 26 | REPORTER_ASSERT(reporter, rr2.isEmpty()); |
| 27 | |
| 28 | rr.setRectXY(r, 20, 20); |
| 29 | rr.inset(19, 19, &rr2); |
| 30 | REPORTER_ASSERT(reporter, rr2.isSimple()); |
| 31 | rr.inset(20, 20, &rr2); |
| 32 | REPORTER_ASSERT(reporter, rr2.isRect()); |
| 33 | } |
| 34 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 35 | // Test out the basic API entry points |
| 36 | static void test_round_rect_basic(skiatest::Reporter* reporter) { |
| 37 | // Test out initialization methods |
reed@google.com | 2b57dc6 | 2013-01-08 13:23:32 +0000 | [diff] [blame] | 38 | SkPoint zeroPt = { 0, 0 }; |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 39 | SkRRect empty; |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 40 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 41 | empty.setEmpty(); |
| 42 | |
| 43 | REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == empty.type()); |
| 44 | REPORTER_ASSERT(reporter, empty.rect().isEmpty()); |
| 45 | |
| 46 | for (int i = 0; i < 4; ++i) { |
| 47 | REPORTER_ASSERT(reporter, zeroPt == empty.radii((SkRRect::Corner) i)); |
| 48 | } |
| 49 | |
| 50 | //---- |
| 51 | SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 52 | |
| 53 | SkRRect rr1; |
| 54 | rr1.setRect(rect); |
| 55 | |
| 56 | REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); |
| 57 | REPORTER_ASSERT(reporter, rr1.rect() == rect); |
| 58 | |
| 59 | for (int i = 0; i < 4; ++i) { |
| 60 | REPORTER_ASSERT(reporter, zeroPt == rr1.radii((SkRRect::Corner) i)); |
| 61 | } |
| 62 | |
| 63 | //---- |
| 64 | SkPoint halfPoint = { SkScalarHalf(kWidth), SkScalarHalf(kHeight) }; |
| 65 | SkRRect rr2; |
| 66 | rr2.setOval(rect); |
| 67 | |
| 68 | REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr2.type()); |
| 69 | REPORTER_ASSERT(reporter, rr2.rect() == rect); |
| 70 | |
| 71 | for (int i = 0; i < 4; ++i) { |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 72 | REPORTER_ASSERT(reporter, |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 73 | rr2.radii((SkRRect::Corner) i).equalsWithinTolerance(halfPoint)); |
| 74 | } |
| 75 | |
| 76 | //---- |
| 77 | SkPoint p = { 5, 5 }; |
| 78 | SkRRect rr3; |
| 79 | rr3.setRectXY(rect, p.fX, p.fY); |
| 80 | |
| 81 | REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr3.type()); |
| 82 | REPORTER_ASSERT(reporter, rr3.rect() == rect); |
| 83 | |
| 84 | for (int i = 0; i < 4; ++i) { |
| 85 | REPORTER_ASSERT(reporter, p == rr3.radii((SkRRect::Corner) i)); |
| 86 | } |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 87 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 88 | //---- |
| 89 | SkPoint radii[4] = { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 } }; |
| 90 | |
| 91 | SkRRect rr4; |
| 92 | rr4.setRectRadii(rect, radii); |
| 93 | |
| 94 | REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr4.type()); |
| 95 | REPORTER_ASSERT(reporter, rr4.rect() == rect); |
| 96 | |
| 97 | for (int i = 0; i < 4; ++i) { |
| 98 | REPORTER_ASSERT(reporter, radii[i] == rr4.radii((SkRRect::Corner) i)); |
| 99 | } |
| 100 | |
| 101 | //---- |
| 102 | SkPoint radii2[4] = { { 0, 0 }, { 0, 0 }, { 50, 50 }, { 20, 50 } }; |
| 103 | |
| 104 | SkRRect rr5; |
| 105 | rr5.setRectRadii(rect, radii2); |
| 106 | |
| 107 | REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr5.type()); |
| 108 | REPORTER_ASSERT(reporter, rr5.rect() == rect); |
| 109 | |
| 110 | for (int i = 0; i < 4; ++i) { |
| 111 | REPORTER_ASSERT(reporter, radii2[i] == rr5.radii((SkRRect::Corner) i)); |
| 112 | } |
| 113 | |
| 114 | // Test out == & != |
| 115 | REPORTER_ASSERT(reporter, empty != rr3); |
| 116 | REPORTER_ASSERT(reporter, rr3 == rr4); |
| 117 | REPORTER_ASSERT(reporter, rr4 != rr5); |
| 118 | } |
| 119 | |
| 120 | // Test out the cases when the RR degenerates to a rect |
| 121 | static void test_round_rect_rects(skiatest::Reporter* reporter) { |
| 122 | SkRect r; |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 123 | static const SkPoint pts[] = { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 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, true, true }; |
| 140 | |
| 141 | SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn)); |
| 142 | |
| 143 | //---- |
| 144 | SkRRect empty; |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 145 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 146 | empty.setEmpty(); |
| 147 | |
| 148 | REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == empty.type()); |
| 149 | r = empty.rect(); |
| 150 | REPORTER_ASSERT(reporter, 0 == r.fLeft && 0 == r.fTop && 0 == r.fRight && 0 == r.fBottom); |
| 151 | |
| 152 | //---- |
| 153 | SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 154 | SkRRect rr1; |
| 155 | rr1.setRectXY(rect, 0, 0); |
| 156 | |
| 157 | REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr1.type()); |
| 158 | r = rr1.rect(); |
| 159 | REPORTER_ASSERT(reporter, rect == r); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 160 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 161 | REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)); |
| 162 | } |
| 163 | |
| 164 | //---- |
| 165 | SkPoint radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }; |
| 166 | |
| 167 | SkRRect rr2; |
| 168 | rr2.setRectRadii(rect, radii); |
| 169 | |
| 170 | REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type()); |
| 171 | r = rr2.rect(); |
| 172 | REPORTER_ASSERT(reporter, rect == r); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 173 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 174 | REPORTER_ASSERT(reporter, isIn[i] == rr2.contains(pts[i].fX, pts[i].fY)); |
| 175 | } |
| 176 | |
| 177 | //---- |
| 178 | SkPoint radii2[4] = { { 0, 0 }, { 20, 20 }, { 50, 50 }, { 20, 50 } }; |
| 179 | |
| 180 | SkRRect rr3; |
| 181 | rr3.setRectRadii(rect, radii2); |
| 182 | REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr3.type()); |
| 183 | } |
| 184 | |
| 185 | // Test out the cases when the RR degenerates to an oval |
| 186 | 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_ScalarRoot2Over2); |
| 189 | static const SkScalar kHeightTol = SkScalarHalf(kHeight) * (SK_Scalar1 - SK_ScalarRoot2Over2); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 190 | static const SkPoint pts[] = { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 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, true, true }; |
| 207 | |
| 208 | SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn)); |
| 209 | |
| 210 | //---- |
| 211 | SkRect oval; |
| 212 | SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 213 | SkRRect rr1; |
| 214 | rr1.setRectXY(rect, SkScalarHalf(kWidth), SkScalarHalf(kHeight)); |
| 215 | |
| 216 | REPORTER_ASSERT(reporter, SkRRect::kOval_Type == rr1.type()); |
| 217 | oval = rr1.rect(); |
| 218 | REPORTER_ASSERT(reporter, oval == rect); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 219 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 220 | REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Test out the non-degenerate RR cases |
| 225 | 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); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 228 | static const SkPoint pts[] = { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 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, true, true }; |
| 245 | |
| 246 | SkASSERT(SK_ARRAY_COUNT(pts) == SK_ARRAY_COUNT(isIn)); |
| 247 | |
| 248 | //---- |
| 249 | SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 250 | SkRRect rr1; |
| 251 | rr1.setRectXY(rect, 20, 20); |
| 252 | |
| 253 | REPORTER_ASSERT(reporter, SkRRect::kSimple_Type == rr1.type()); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 254 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 255 | REPORTER_ASSERT(reporter, isIn[i] == rr1.contains(pts[i].fX, pts[i].fY)); |
| 256 | } |
| 257 | |
| 258 | //---- |
| 259 | static const SkScalar kDist50 = 50*(SK_Scalar1 - SK_ScalarRoot2Over2); |
skia.committer@gmail.com | c3d7d90 | 2012-11-30 02:01:24 +0000 | [diff] [blame] | 260 | static const SkPoint pts2[] = { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 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 } }; |
| 280 | |
| 281 | SkRRect rr2; |
| 282 | rr2.setRectRadii(rect, radii); |
| 283 | |
| 284 | REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr2.type()); |
robertphillips@google.com | 93f0332 | 2012-12-03 17:35:19 +0000 | [diff] [blame] | 285 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 286 | REPORTER_ASSERT(reporter, isIn[i] == rr2.contains(pts2[i].fX, pts2[i].fY)); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | // Test out questionable-parameter handling |
| 291 | static void test_round_rect_iffy_parameters(skiatest::Reporter* reporter) { |
| 292 | |
| 293 | // When the radii exceed the base rect they are proportionally scaled down |
| 294 | // to fit |
| 295 | SkRect rect = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 296 | SkPoint radii[4] = { { 50, 100 }, { 100, 50 }, { 50, 100 }, { 100, 50 } }; |
| 297 | |
| 298 | SkRRect rr1; |
| 299 | rr1.setRectRadii(rect, radii); |
| 300 | |
| 301 | REPORTER_ASSERT(reporter, SkRRect::kComplex_Type == rr1.type()); |
| 302 | |
| 303 | const SkPoint& p = rr1.radii(SkRRect::kUpperLeft_Corner); |
| 304 | |
| 305 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(p.fX, 33.33333f)); |
| 306 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(p.fY, 66.66666f)); |
| 307 | |
| 308 | // Negative radii should be capped at zero |
| 309 | SkRRect rr2; |
| 310 | rr2.setRectXY(rect, -10, -20); |
| 311 | |
| 312 | REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type()); |
| 313 | |
| 314 | const SkPoint& p2 = rr2.radii(SkRRect::kUpperLeft_Corner); |
| 315 | |
| 316 | REPORTER_ASSERT(reporter, 0.0f == p2.fX); |
| 317 | REPORTER_ASSERT(reporter, 0.0f == p2.fY); |
| 318 | } |
| 319 | |
robertphillips@google.com | 32c1b66 | 2013-04-25 12:23:00 +0000 | [diff] [blame] | 320 | // Move a small box from the start position by (stepX, stepY) 'numSteps' times |
| 321 | // testing for containment in 'rr' at each step. |
| 322 | static void test_direction(skiatest::Reporter* reporter, const SkRRect &rr, |
| 323 | SkScalar initX, int stepX, SkScalar initY, int stepY, |
| 324 | int numSteps, const bool* contains) { |
| 325 | SkScalar x = initX, y = initY; |
| 326 | for (int i = 0; i < numSteps; ++i) { |
| 327 | SkRect test = SkRect::MakeXYWH(x, y, |
| 328 | stepX ? SkIntToScalar(stepX) : SK_Scalar1, |
| 329 | stepY ? SkIntToScalar(stepY) : SK_Scalar1); |
| 330 | test.sort(); |
| 331 | |
| 332 | REPORTER_ASSERT(reporter, contains[i] == rr.contains(test)); |
| 333 | |
| 334 | x += stepX; |
| 335 | y += stepY; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | // Exercise the RR's contains rect method |
| 340 | static void test_round_rect_contains_rect(skiatest::Reporter* reporter) { |
| 341 | |
| 342 | static const int kNumRRects = 4; |
| 343 | static const SkVector gRadii[kNumRRects][4] = { |
| 344 | { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }, // rect |
| 345 | { { 20, 20 }, { 20, 20 }, { 20, 20 }, { 20, 20 } }, // circle |
| 346 | { { 10, 10 }, { 10, 10 }, { 10, 10 }, { 10, 10 } }, // simple |
| 347 | { { 0, 0 }, { 20, 20 }, { 10, 10 }, { 30, 30 } } // complex |
| 348 | }; |
| 349 | |
| 350 | SkRRect rrects[kNumRRects]; |
| 351 | for (int i = 0; i < kNumRRects; ++i) { |
| 352 | rrects[i].setRectRadii(SkRect::MakeWH(40, 40), gRadii[i]); |
| 353 | } |
| 354 | |
| 355 | // First test easy outs - boxes that are obviously out on |
| 356 | // each corner and edge |
| 357 | static const SkRect easyOuts[] = { |
| 358 | { -5, -5, 5, 5 }, // NW |
| 359 | { 15, -5, 20, 5 }, // N |
| 360 | { 35, -5, 45, 5 }, // NE |
| 361 | { 35, 15, 45, 20 }, // E |
| 362 | { 35, 45, 35, 45 }, // SE |
| 363 | { 15, 35, 20, 45 }, // S |
| 364 | { -5, 35, 5, 45 }, // SW |
| 365 | { -5, 15, 5, 20 } // W |
| 366 | }; |
| 367 | |
| 368 | for (int i = 0; i < kNumRRects; ++i) { |
| 369 | for (size_t j = 0; j < SK_ARRAY_COUNT(easyOuts); ++j) { |
| 370 | REPORTER_ASSERT(reporter, !rrects[i].contains(easyOuts[j])); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | // Now test non-trivial containment. For each compass |
| 375 | // point walk a 1x1 rect in from the edge of the bounding |
| 376 | // rect |
| 377 | static const int kNumSteps = 15; |
| 378 | bool answers[kNumRRects][8][kNumSteps] = { |
| 379 | // all the test rects are inside the degenerate rrect |
| 380 | { |
| 381 | // rect |
| 382 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 383 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 384 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 385 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 386 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 387 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 388 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 389 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 390 | }, |
| 391 | // for the circle we expect 6 blocks to be out on the |
| 392 | // corners (then the rest in) and only the first block |
| 393 | // out on the vertical and horizontal axes (then |
| 394 | // the rest in) |
| 395 | { |
| 396 | // circle |
| 397 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 398 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 399 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 400 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 401 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 402 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 403 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 404 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 405 | }, |
| 406 | // for the simple round rect we expect 3 out on |
| 407 | // the corners (then the rest in) and no blocks out |
| 408 | // on the vertical and horizontal axes |
| 409 | { |
| 410 | // simple RR |
| 411 | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 412 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 413 | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 414 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 415 | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 416 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 417 | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 418 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 419 | }, |
| 420 | // for the complex case the answer is different for each direction |
| 421 | { |
| 422 | // complex RR |
| 423 | // all in for NW (rect) corner (same as rect case) |
| 424 | { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 425 | // only first block out for N (same as circle case) |
| 426 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 427 | // first 6 blocks out for NE (same as circle case) |
| 428 | { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 429 | // only first block out for E (same as circle case) |
| 430 | { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 431 | // first 3 blocks out for SE (same as simple case) |
| 432 | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 433 | // first two blocks out for S |
| 434 | { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 435 | // first 9 blocks out for SW |
| 436 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }, |
| 437 | // first two blocks out for W (same as S) |
| 438 | { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 439 | } |
| 440 | }; |
| 441 | |
| 442 | for (int i = 0; i < kNumRRects; ++i) { |
| 443 | test_direction(reporter, rrects[i], 0, 1, 0, 1, kNumSteps, answers[i][0]); // NW |
| 444 | test_direction(reporter, rrects[i], 19.5f, 0, 0, 1, kNumSteps, answers[i][1]); // N |
| 445 | test_direction(reporter, rrects[i], 40, -1, 0, 1, kNumSteps, answers[i][2]); // NE |
| 446 | test_direction(reporter, rrects[i], 40, -1, 19.5f, 0, kNumSteps, answers[i][3]); // E |
| 447 | test_direction(reporter, rrects[i], 40, -1, 40, -1, kNumSteps, answers[i][4]); // SE |
| 448 | test_direction(reporter, rrects[i], 19.5f, 0, 40, -1, kNumSteps, answers[i][5]); // S |
| 449 | test_direction(reporter, rrects[i], 0, 1, 40, -1, kNumSteps, answers[i][6]); // SW |
| 450 | test_direction(reporter, rrects[i], 0, 1, 19.5f, 0, kNumSteps, answers[i][7]); // W |
| 451 | } |
| 452 | } |
| 453 | |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 454 | static void TestRoundRect(skiatest::Reporter* reporter) { |
| 455 | test_round_rect_basic(reporter); |
| 456 | test_round_rect_rects(reporter); |
| 457 | test_round_rect_ovals(reporter); |
| 458 | test_round_rect_general(reporter); |
| 459 | test_round_rect_iffy_parameters(reporter); |
mike@reedtribe.org | bcbef57 | 2012-12-23 23:11:21 +0000 | [diff] [blame] | 460 | test_inset(reporter); |
robertphillips@google.com | 32c1b66 | 2013-04-25 12:23:00 +0000 | [diff] [blame] | 461 | test_round_rect_contains_rect(reporter); |
robertphillips@google.com | 5985e7c | 2012-11-29 13:24:55 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | #include "TestClassDef.h" |
| 465 | DEFINE_TESTCLASS("RoundRect", TestRoundRectClass, TestRoundRect) |