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

Side by Side Diff: tests/RTreeTest.cpp

Issue 508873004: Revert of Convert BBH APIs to use SkRect. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 months 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
« no previous file with comments | « tests/PictureTest.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | 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 "SkRTree.h" 8 #include "SkRTree.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "SkTSort.h" 10 #include "SkTSort.h"
11 #include "Test.h" 11 #include "Test.h"
12 12
13 static const size_t MIN_CHILDREN = 6; 13 static const size_t MIN_CHILDREN = 6;
14 static const size_t MAX_CHILDREN = 11; 14 static const size_t MAX_CHILDREN = 11;
15 15
16 static const int NUM_RECTS = 200; 16 static const int NUM_RECTS = 200;
17 static const size_t NUM_ITERATIONS = 100; 17 static const size_t NUM_ITERATIONS = 100;
18 static const size_t NUM_QUERIES = 50; 18 static const size_t NUM_QUERIES = 50;
19 19
20 struct DataRect { 20 struct DataRect {
21 SkRect rect; 21 SkIRect rect;
22 void* data; 22 void* data;
23 }; 23 };
24 24
25 static SkRect random_rect(SkRandom& rand) { 25 static SkIRect random_rect(SkRandom& rand) {
26 SkRect rect = {0,0,0,0}; 26 SkIRect rect = {0,0,0,0};
27 while (rect.isEmpty()) { 27 while (rect.isEmpty()) {
28 rect.fLeft = rand.nextRangeF(0, 1000); 28 rect.fLeft = rand.nextS() % 1000;
29 rect.fRight = rand.nextRangeF(0, 1000); 29 rect.fRight = rand.nextS() % 1000;
30 rect.fTop = rand.nextRangeF(0, 1000); 30 rect.fTop = rand.nextS() % 1000;
31 rect.fBottom = rand.nextRangeF(0, 1000); 31 rect.fBottom = rand.nextS() % 1000;
32 rect.sort(); 32 rect.sort();
33 } 33 }
34 return rect; 34 return rect;
35 } 35 }
36 36
37 static void random_data_rects(SkRandom& rand, DataRect out[], int n) { 37 static void random_data_rects(SkRandom& rand, DataRect out[], int n) {
38 for (int i = 0; i < n; ++i) { 38 for (int i = 0; i < n; ++i) {
39 out[i].rect = random_rect(rand); 39 out[i].rect = random_rect(rand);
40 out[i].data = reinterpret_cast<void*>(i); 40 out[i].data = reinterpret_cast<void*>(i);
41 } 41 }
42 } 42 }
43 43
44 static bool verify_query(SkRect query, DataRect rects[], 44 static bool verify_query(SkIRect query, DataRect rects[],
45 SkTDArray<void*>& found) { 45 SkTDArray<void*>& found) {
46 // TODO(mtklein): no need to do this after everything's SkRects
47 query.roundOut();
48
49 SkTDArray<void*> expected; 46 SkTDArray<void*> expected;
50
51 // manually intersect with every rectangle 47 // manually intersect with every rectangle
52 for (int i = 0; i < NUM_RECTS; ++i) { 48 for (int i = 0; i < NUM_RECTS; ++i) {
53 if (SkRect::Intersects(query, rects[i].rect)) { 49 if (SkIRect::IntersectsNoEmptyCheck(query, rects[i].rect)) {
54 expected.push(rects[i].data); 50 expected.push(rects[i].data);
55 } 51 }
56 } 52 }
57 53
58 if (expected.count() != found.count()) { 54 if (expected.count() != found.count()) {
59 return false; 55 return false;
60 } 56 }
61 57
62 if (0 == expected.count()) { 58 if (0 == expected.count()) {
63 return true; 59 return true;
64 } 60 }
65 61
66 // Just cast to long since sorting by the value of the void*'s was being pro blematic... 62 // Just cast to long since sorting by the value of the void*'s was being pro blematic...
67 SkTQSort(reinterpret_cast<long*>(expected.begin()), 63 SkTQSort(reinterpret_cast<long*>(expected.begin()),
68 reinterpret_cast<long*>(expected.end() - 1)); 64 reinterpret_cast<long*>(expected.end() - 1));
69 SkTQSort(reinterpret_cast<long*>(found.begin()), 65 SkTQSort(reinterpret_cast<long*>(found.begin()),
70 reinterpret_cast<long*>(found.end() - 1)); 66 reinterpret_cast<long*>(found.end() - 1));
71 return found == expected; 67 return found == expected;
72 } 68 }
73 69
74 static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, DataRect r ects[], 70 static void run_queries(skiatest::Reporter* reporter, SkRandom& rand, DataRect r ects[],
75 SkRTree& tree) { 71 SkRTree& tree) {
76 for (size_t i = 0; i < NUM_QUERIES; ++i) { 72 for (size_t i = 0; i < NUM_QUERIES; ++i) {
77 SkTDArray<void*> hits; 73 SkTDArray<void*> hits;
78 SkRect query = random_rect(rand); 74 SkIRect query = random_rect(rand);
79 tree.search(query, &hits); 75 tree.search(query, &hits);
80 REPORTER_ASSERT(reporter, verify_query(query, rects, hits)); 76 REPORTER_ASSERT(reporter, verify_query(query, rects, hits));
81 } 77 }
82 } 78 }
83 79
84 static void rtree_test_main(SkRTree* rtree, skiatest::Reporter* reporter) { 80 static void rtree_test_main(SkRTree* rtree, skiatest::Reporter* reporter) {
85 DataRect rects[NUM_RECTS]; 81 DataRect rects[NUM_RECTS];
86 SkRandom rand; 82 SkRandom rand;
87 REPORTER_ASSERT(reporter, NULL != rtree); 83 REPORTER_ASSERT(reporter, NULL != rtree);
88 84
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 DEF_TEST(RTree, reporter) { 141 DEF_TEST(RTree, reporter) {
146 SkRTree* rtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN); 142 SkRTree* rtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN);
147 SkAutoUnref au(rtree); 143 SkAutoUnref au(rtree);
148 rtree_test_main(rtree, reporter); 144 rtree_test_main(rtree, reporter);
149 145
150 // Rtree that orders input rectangles on deferred insert. 146 // Rtree that orders input rectangles on deferred insert.
151 SkRTree* unsortedRtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN, 1, fals e); 147 SkRTree* unsortedRtree = SkRTree::Create(MIN_CHILDREN, MAX_CHILDREN, 1, fals e);
152 SkAutoUnref auo(unsortedRtree); 148 SkAutoUnref auo(unsortedRtree);
153 rtree_test_main(unsortedRtree, reporter); 149 rtree_test_main(unsortedRtree, reporter);
154 } 150 }
OLDNEW
« no previous file with comments | « tests/PictureTest.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698