| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "SkRegion.h" | 9 #include "SkRegion.h" |
| 10 #include "SkRandom.h" | 10 #include "SkRandom.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 REPORTER_ASSERT(reporter, !empty.contains(empty2)); | 91 REPORTER_ASSERT(reporter, !empty.contains(empty2)); |
| 92 REPORTER_ASSERT(reporter, !valid.contains(empty)); | 92 REPORTER_ASSERT(reporter, !valid.contains(empty)); |
| 93 REPORTER_ASSERT(reporter, !empty.contains(valid)); | 93 REPORTER_ASSERT(reporter, !empty.contains(valid)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 enum { | 96 enum { |
| 97 W = 256, | 97 W = 256, |
| 98 H = 256 | 98 H = 256 |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 static SkIRect randRect(SkMWCRandom& rand) { | 101 static SkIRect randRect(SkRandom& rand) { |
| 102 int x = rand.nextU() % W; | 102 int x = rand.nextU() % W; |
| 103 int y = rand.nextU() % H; | 103 int y = rand.nextU() % H; |
| 104 int w = rand.nextU() % W; | 104 int w = rand.nextU() % W; |
| 105 int h = rand.nextU() % H; | 105 int h = rand.nextU() % H; |
| 106 return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1); | 106 return SkIRect::MakeXYWH(x, y, w >> 1, h >> 1); |
| 107 } | 107 } |
| 108 | 108 |
| 109 static void randRgn(SkMWCRandom& rand, SkRegion* rgn, int n) { | 109 static void randRgn(SkRandom& rand, SkRegion* rgn, int n) { |
| 110 rgn->setEmpty(); | 110 rgn->setEmpty(); |
| 111 for (int i = 0; i < n; ++i) { | 111 for (int i = 0; i < n; ++i) { |
| 112 rgn->op(randRect(rand), SkRegion::kUnion_Op); | 112 rgn->op(randRect(rand), SkRegion::kUnion_Op); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 static bool slow_contains(const SkRegion& outer, const SkRegion& inner) { | 116 static bool slow_contains(const SkRegion& outer, const SkRegion& inner) { |
| 117 SkRegion tmp; | 117 SkRegion tmp; |
| 118 tmp.op(outer, inner, SkRegion::kUnion_Op); | 118 tmp.op(outer, inner, SkRegion::kUnion_Op); |
| 119 return outer == tmp; | 119 return outer == tmp; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 bool c1 = slow_intersects(a, b); | 176 bool c1 = slow_intersects(a, b); |
| 177 REPORTER_ASSERT(reporter, c0 == c1); | 177 REPORTER_ASSERT(reporter, c0 == c1); |
| 178 | 178 |
| 179 test_intersects_iter(reporter, a); | 179 test_intersects_iter(reporter, a); |
| 180 test_intersects_iter(reporter, b); | 180 test_intersects_iter(reporter, b); |
| 181 } | 181 } |
| 182 | 182 |
| 183 static void test_proc(skiatest::Reporter* reporter, | 183 static void test_proc(skiatest::Reporter* reporter, |
| 184 void (*proc)(skiatest::Reporter*, | 184 void (*proc)(skiatest::Reporter*, |
| 185 const SkRegion& a, const SkRegion&)) { | 185 const SkRegion& a, const SkRegion&)) { |
| 186 SkMWCRandom rand; | 186 SkRandom rand; |
| 187 for (int i = 0; i < 10000; ++i) { | 187 for (int i = 0; i < 10000; ++i) { |
| 188 SkRegion outer; | 188 SkRegion outer; |
| 189 randRgn(rand, &outer, 8); | 189 randRgn(rand, &outer, 8); |
| 190 SkRegion inner; | 190 SkRegion inner; |
| 191 randRgn(rand, &inner, 2); | 191 randRgn(rand, &inner, 2); |
| 192 proc(reporter, outer, inner); | 192 proc(reporter, outer, inner); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 static void rand_rect(SkIRect* rect, SkMWCRandom& rand) { | 196 static void rand_rect(SkIRect* rect, SkRandom& rand) { |
| 197 int bits = 6; | 197 int bits = 6; |
| 198 int shift = 32 - bits; | 198 int shift = 32 - bits; |
| 199 rect->set(rand.nextU() >> shift, rand.nextU() >> shift, | 199 rect->set(rand.nextU() >> shift, rand.nextU() >> shift, |
| 200 rand.nextU() >> shift, rand.nextU() >> shift); | 200 rand.nextU() >> shift, rand.nextU() >> shift); |
| 201 rect->sort(); | 201 rect->sort(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 static bool test_rects(const SkIRect rect[], int count) { | 204 static bool test_rects(const SkIRect rect[], int count) { |
| 205 SkRegion rgn0, rgn1; | 205 SkRegion rgn0, rgn1; |
| 206 | 206 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 230 REPORTER_ASSERT(reporter, test_rects(r2, SK_ARRAY_COUNT(r2))); | 230 REPORTER_ASSERT(reporter, test_rects(r2, SK_ARRAY_COUNT(r2))); |
| 231 | 231 |
| 232 const SkIRect rects[] = { | 232 const SkIRect rects[] = { |
| 233 { 0, 0, 1, 2 }, | 233 { 0, 0, 1, 2 }, |
| 234 { 2, 1, 3, 3 }, | 234 { 2, 1, 3, 3 }, |
| 235 { 4, 0, 5, 1 }, | 235 { 4, 0, 5, 1 }, |
| 236 { 6, 0, 7, 4 }, | 236 { 6, 0, 7, 4 }, |
| 237 }; | 237 }; |
| 238 REPORTER_ASSERT(reporter, test_rects(rects, SK_ARRAY_COUNT(rects))); | 238 REPORTER_ASSERT(reporter, test_rects(rects, SK_ARRAY_COUNT(rects))); |
| 239 | 239 |
| 240 SkMWCRandom rand; | 240 SkRandom rand; |
| 241 for (int i = 0; i < 1000; i++) { | 241 for (int i = 0; i < 1000; i++) { |
| 242 SkRegion rgn0, rgn1; | 242 SkRegion rgn0, rgn1; |
| 243 | 243 |
| 244 const int N = 8; | 244 const int N = 8; |
| 245 SkIRect rect[N]; | 245 SkIRect rect[N]; |
| 246 for (int j = 0; j < N; j++) { | 246 for (int j = 0; j < N; j++) { |
| 247 rand_rect(&rect[j], rand); | 247 rand_rect(&rect[j], rand); |
| 248 } | 248 } |
| 249 REPORTER_ASSERT(reporter, test_rects(rect, N)); | 249 REPORTER_ASSERT(reporter, test_rects(rect, N)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 test_proc(reporter, contains_proc); | 252 test_proc(reporter, contains_proc); |
| 253 test_proc(reporter, intersects_proc); | 253 test_proc(reporter, intersects_proc); |
| 254 test_empties(reporter); | 254 test_empties(reporter); |
| 255 test_fromchrome(reporter); | 255 test_fromchrome(reporter); |
| 256 } | 256 } |
| 257 | 257 |
| 258 #include "TestClassDef.h" | 258 #include "TestClassDef.h" |
| 259 DEFINE_TESTCLASS("Region", RegionTestClass, TestRegion) | 259 DEFINE_TESTCLASS("Region", RegionTestClass, TestRegion) |
| OLD | NEW |