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 "SkRTree.h" | 8 #include "SkRTree.h" |
9 #include "SkTSort.h" | 9 #include "SkTSort.h" |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 fRoot = this->bulkLoad(&fDeferredInserts); | 95 fRoot = this->bulkLoad(&fDeferredInserts); |
96 } | 96 } |
97 } else { | 97 } else { |
98 // TODO: some algorithm for bulk loading into an already populated tree | 98 // TODO: some algorithm for bulk loading into an already populated tree |
99 SkASSERT(0 == fDeferredInserts.count()); | 99 SkASSERT(0 == fDeferredInserts.count()); |
100 } | 100 } |
101 fDeferredInserts.rewind(); | 101 fDeferredInserts.rewind(); |
102 this->validate(); | 102 this->validate(); |
103 } | 103 } |
104 | 104 |
105 void SkRTree::search(const SkIRect& query, SkTDArray<void*>* results) { | 105 void SkRTree::search(const SkIRect& query, SkTDArray<void*>* results) const { |
106 this->validate(); | 106 this->validate(); |
107 if (0 != fDeferredInserts.count()) { | 107 SkASSERT(0 == fDeferredInserts.count()); // If this fails, you should have
flushed. |
108 this->flushDeferredInserts(); | |
109 } | |
110 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query
)) { | 108 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query
)) { |
111 this->search(fRoot.fChild.subtree, query, results); | 109 this->search(fRoot.fChild.subtree, query, results); |
112 } | 110 } |
113 this->validate(); | 111 this->validate(); |
114 } | 112 } |
115 | 113 |
116 void SkRTree::clear() { | 114 void SkRTree::clear() { |
117 this->validate(); | 115 this->validate(); |
118 fNodes.reset(); | 116 fNodes.reset(); |
119 fDeferredInserts.rewind(); | 117 fDeferredInserts.rewind(); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 } | 390 } |
393 (*branches)[newBranches] = b; | 391 (*branches)[newBranches] = b; |
394 ++newBranches; | 392 ++newBranches; |
395 } | 393 } |
396 } | 394 } |
397 branches->setCount(newBranches); | 395 branches->setCount(newBranches); |
398 return this->bulkLoad(branches, level + 1); | 396 return this->bulkLoad(branches, level + 1); |
399 } | 397 } |
400 } | 398 } |
401 | 399 |
402 void SkRTree::validate() { | 400 void SkRTree::validate() const { |
403 #ifdef SK_DEBUG | 401 #ifdef SK_DEBUG |
404 if (this->isEmpty()) { | 402 if (this->isEmpty()) { |
405 return; | 403 return; |
406 } | 404 } |
407 SkASSERT(fCount == this->validateSubtree(fRoot.fChild.subtree, fRoot.fBounds
, true)); | 405 SkASSERT(fCount == this->validateSubtree(fRoot.fChild.subtree, fRoot.fBounds
, true)); |
408 #endif | 406 #endif |
409 } | 407 } |
410 | 408 |
411 int SkRTree::validateSubtree(Node* root, SkIRect bounds, bool isRoot) { | 409 int SkRTree::validateSubtree(Node* root, SkIRect bounds, bool isRoot) const { |
412 // make sure the pointer is pointing to a valid place | 410 // make sure the pointer is pointing to a valid place |
413 SkASSERT(fNodes.contains(static_cast<void*>(root))); | 411 SkASSERT(fNodes.contains(static_cast<void*>(root))); |
414 | 412 |
415 if (isRoot) { | 413 if (isRoot) { |
416 // If the root of this subtree is the overall root, we have looser stand
ards: | 414 // If the root of this subtree is the overall root, we have looser stand
ards: |
417 if (root->isLeaf()) { | 415 if (root->isLeaf()) { |
418 SkASSERT(root->fNumChildren >= 1 && root->fNumChildren <= fMaxChildr
en); | 416 SkASSERT(root->fNumChildren >= 1 && root->fNumChildren <= fMaxChildr
en); |
419 } else { | 417 } else { |
420 SkASSERT(root->fNumChildren >= 2 && root->fNumChildren <= fMaxChildr
en); | 418 SkASSERT(root->fNumChildren >= 2 && root->fNumChildren <= fMaxChildr
en); |
421 } | 419 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 471 |
474 // Expand 'out' to include 'joinWith' | 472 // Expand 'out' to include 'joinWith' |
475 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { | 473 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { |
476 // since we check for empty bounds on insert, we know we'll never have empty
rects | 474 // since we check for empty bounds on insert, we know we'll never have empty
rects |
477 // and we can save the empty check that SkIRect::join requires | 475 // and we can save the empty check that SkIRect::join requires |
478 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } | 476 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } |
479 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } | 477 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } |
480 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } | 478 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } |
481 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } | 479 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } |
482 } | 480 } |
OLD | NEW |