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 "Test.h" | 8 #include "Test.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "SkQuadTree.h" | 10 #include "SkQuadTree.h" |
11 #include "SkRTree.h" | 11 #include "SkRTree.h" |
12 #include "SkTSort.h" | 12 #include "SkTSort.h" |
13 | 13 |
14 static const size_t RTREE_MIN_CHILDREN = 6; | 14 static const size_t RTREE_MIN_CHILDREN = 6; |
15 static const size_t RTREE_MAX_CHILDREN = 11; | 15 static const size_t RTREE_MAX_CHILDREN = 11; |
16 static const size_t QUADTREE_MIN_CHILDREN = 4; | 16 static const size_t QUADTREE_MIN_CHILDREN = 0; |
17 static const size_t QUADTREE_MAX_CHILDREN = 0; // No hard limit for quadtree | 17 static const size_t QUADTREE_MAX_CHILDREN = 0; // No hard limit for quadtree |
18 | 18 |
19 static const int NUM_RECTS = 200; | 19 static const int NUM_RECTS = 200; |
20 static const size_t NUM_ITERATIONS = 100; | 20 static const size_t NUM_ITERATIONS = 100; |
21 static const size_t NUM_QUERIES = 50; | 21 static const size_t NUM_QUERIES = 50; |
22 | 22 |
23 static const int MAX_SIZE = 1000; | 23 static const int MAX_SIZE = 1000; |
24 | 24 |
25 struct DataRect { | 25 struct DataRect { |
26 SkIRect rect; | 26 SkIRect rect; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 tree->flushDeferredInserts(); | 119 tree->flushDeferredInserts(); |
120 run_queries(reporter, rand, rects, *tree); | 120 run_queries(reporter, rand, rects, *tree); |
121 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); | 121 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); |
122 REPORTER_ASSERT(reporter, | 122 REPORTER_ASSERT(reporter, |
123 ((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth()))
&& | 123 ((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth()))
&& |
124 ((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())))
; | 124 ((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())))
; |
125 tree->clear(); | 125 tree->clear(); |
126 REPORTER_ASSERT(reporter, 0 == tree->getCount()); | 126 REPORTER_ASSERT(reporter, 0 == tree->getCount()); |
127 | 127 |
128 // Then try immediate inserts | 128 // Then try immediate inserts |
129 for (int i = 0; i < NUM_RECTS; ++i) { | 129 tree->insert(rects[0].data, rects[0].rect); |
| 130 tree->flushDeferredInserts(); |
| 131 for (int i = 1; i < NUM_RECTS; ++i) { |
130 tree->insert(rects[i].data, rects[i].rect); | 132 tree->insert(rects[i].data, rects[i].rect); |
131 } | 133 } |
132 run_queries(reporter, rand, rects, *tree); | 134 run_queries(reporter, rand, rects, *tree); |
133 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); | 135 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); |
134 REPORTER_ASSERT(reporter, | 136 REPORTER_ASSERT(reporter, |
135 ((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth()))
&& | 137 ((expectedDepthMin <= 0) || (expectedDepthMin <= tree->getDepth()))
&& |
136 ((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())))
; | 138 ((expectedDepthMax <= 0) || (expectedDepthMax >= tree->getDepth())))
; |
137 tree->clear(); | 139 tree->clear(); |
138 REPORTER_ASSERT(reporter, 0 == tree->getCount()); | 140 REPORTER_ASSERT(reporter, 0 == tree->getCount()); |
139 | 141 |
140 // And for good measure try immediate inserts, but in reversed order | 142 // And for good measure try immediate inserts, but in reversed order |
141 for (int i = NUM_RECTS - 1; i >= 0; --i) { | 143 tree->insert(rects[NUM_RECTS - 1].data, rects[NUM_RECTS - 1].rect); |
| 144 tree->flushDeferredInserts(); |
| 145 for (int i = NUM_RECTS - 2; i >= 0; --i) { |
142 tree->insert(rects[i].data, rects[i].rect); | 146 tree->insert(rects[i].data, rects[i].rect); |
143 } | 147 } |
144 run_queries(reporter, rand, rects, *tree); | 148 run_queries(reporter, rand, rects, *tree); |
145 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); | 149 REPORTER_ASSERT(reporter, NUM_RECTS == tree->getCount()); |
146 REPORTER_ASSERT(reporter, | 150 REPORTER_ASSERT(reporter, |
147 ((expectedDepthMin < 0) || (expectedDepthMin <= tree->getDepth())) &
& | 151 ((expectedDepthMin < 0) || (expectedDepthMin <= tree->getDepth())) &
& |
148 ((expectedDepthMax < 0) || (expectedDepthMax >= tree->getDepth()))); | 152 ((expectedDepthMax < 0) || (expectedDepthMax >= tree->getDepth()))); |
149 tree->clear(); | 153 tree->clear(); |
150 REPORTER_ASSERT(reporter, 0 == tree->getCount()); | 154 REPORTER_ASSERT(reporter, 0 == tree->getCount()); |
151 } | 155 } |
152 } | 156 } |
153 | 157 |
154 DEF_TEST(BBoxHierarchy, reporter) { | 158 DEF_TEST(BBoxHierarchy, reporter) { |
155 // RTree | 159 // RTree |
156 { | 160 { |
157 SkRTree* rtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN)
; | 161 SkRTree* rtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN)
; |
158 SkAutoUnref au(rtree); | 162 SkAutoUnref au(rtree); |
159 tree_test_main(rtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, reporter); | 163 tree_test_main(rtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, reporter); |
160 | 164 |
161 // Rtree that orders input rectangles on deferred insert. | 165 // Rtree that orders input rectangles on deferred insert. |
162 SkRTree* unsortedRtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_C
HILDREN, 1, false); | 166 SkRTree* unsortedRtree = SkRTree::Create(RTREE_MIN_CHILDREN, RTREE_MAX_C
HILDREN, 1, false); |
163 SkAutoUnref auo(unsortedRtree); | 167 SkAutoUnref auo(unsortedRtree); |
164 tree_test_main(unsortedRtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, re
porter); | 168 tree_test_main(unsortedRtree, RTREE_MIN_CHILDREN, RTREE_MAX_CHILDREN, re
porter); |
165 } | 169 } |
166 | 170 |
167 // QuadTree | 171 // QuadTree |
168 { | 172 { |
169 SkQuadTree* quadtree = SkQuadTree::Create( | 173 SkQuadTree* quadtree = SkNEW_ARGS(SkQuadTree, ( |
170 SkIRect::MakeLTRB(-MAX_SIZE, -MAX_SIZE, MAX_SIZE, MAX_SIZE)); | 174 SkIRect::MakeLTRB(-MAX_SIZE, -MAX_SIZE, MAX_SIZE, MAX_SIZE))); |
171 SkAutoUnref au(quadtree); | 175 SkAutoUnref au(quadtree); |
172 tree_test_main(quadtree, QUADTREE_MIN_CHILDREN, QUADTREE_MAX_CHILDREN, r
eporter); | 176 tree_test_main(quadtree, QUADTREE_MIN_CHILDREN, QUADTREE_MAX_CHILDREN, r
eporter); |
173 | 177 |
174 // QuadTree that orders input rectangles on deferred insert. | 178 // QuadTree that orders input rectangles on deferred insert. |
175 SkQuadTree* unsortedQuadTree = SkQuadTree::Create( | 179 SkQuadTree* unsortedQuadTree = SkNEW_ARGS(SkQuadTree, ( |
176 SkIRect::MakeLTRB(-MAX_SIZE, -MAX_SIZE, MAX_SIZE, MAX_SIZE)); | 180 SkIRect::MakeLTRB(-MAX_SIZE, -MAX_SIZE, MAX_SIZE, MAX_SIZE))); |
177 SkAutoUnref auo(unsortedQuadTree); | 181 SkAutoUnref auo(unsortedQuadTree); |
178 tree_test_main(unsortedQuadTree, QUADTREE_MIN_CHILDREN, QUADTREE_MAX_CHI
LDREN, reporter); | 182 tree_test_main(unsortedQuadTree, QUADTREE_MIN_CHILDREN, QUADTREE_MAX_CHI
LDREN, reporter); |
179 } | 183 } |
180 } | 184 } |
OLD | NEW |