| 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 26 matching lines...) Expand all Loading... |
| 37 SkASSERT(minChildren < maxChildren && minChildren > 0 && maxChildren < | 37 SkASSERT(minChildren < maxChildren && minChildren > 0 && maxChildren < |
| 38 static_cast<int>(SK_MaxU16)); | 38 static_cast<int>(SK_MaxU16)); |
| 39 SkASSERT((maxChildren + 1) / 2 >= minChildren); | 39 SkASSERT((maxChildren + 1) / 2 >= minChildren); |
| 40 this->validate(); | 40 this->validate(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 SkRTree::~SkRTree() { | 43 SkRTree::~SkRTree() { |
| 44 this->clear(); | 44 this->clear(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void SkRTree::insert(void* data, const SkIRect& bounds, bool defer) { | 47 void SkRTree::insert(void* data, const SkRect& fbounds, bool defer) { |
| 48 SkIRect bounds; |
| 49 if (fbounds.isLargest()) { |
| 50 bounds.setLargest(); |
| 51 } else { |
| 52 fbounds.roundOut(&bounds); |
| 53 } |
| 54 |
| 48 this->validate(); | 55 this->validate(); |
| 49 if (bounds.isEmpty()) { | 56 if (bounds.isEmpty()) { |
| 50 SkASSERT(false); | 57 SkASSERT(false); |
| 51 return; | 58 return; |
| 52 } | 59 } |
| 53 Branch newBranch; | 60 Branch newBranch; |
| 54 newBranch.fBounds = bounds; | 61 newBranch.fBounds = bounds; |
| 55 newBranch.fChild.data = data; | 62 newBranch.fChild.data = data; |
| 56 if (this->isEmpty()) { | 63 if (this->isEmpty()) { |
| 57 // since a bulk-load into an existing tree is as of yet unimplemented (a
nd arguably not | 64 // since a bulk-load into an existing tree is as of yet unimplemented (a
nd arguably not |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 fRoot = this->bulkLoad(&fDeferredInserts); | 102 fRoot = this->bulkLoad(&fDeferredInserts); |
| 96 } | 103 } |
| 97 } else { | 104 } else { |
| 98 // TODO: some algorithm for bulk loading into an already populated tree | 105 // TODO: some algorithm for bulk loading into an already populated tree |
| 99 SkASSERT(0 == fDeferredInserts.count()); | 106 SkASSERT(0 == fDeferredInserts.count()); |
| 100 } | 107 } |
| 101 fDeferredInserts.rewind(); | 108 fDeferredInserts.rewind(); |
| 102 this->validate(); | 109 this->validate(); |
| 103 } | 110 } |
| 104 | 111 |
| 105 void SkRTree::search(const SkIRect& query, SkTDArray<void*>* results) const { | 112 void SkRTree::search(const SkRect& fquery, SkTDArray<void*>* results) const { |
| 113 SkIRect query; |
| 114 fquery.roundOut(&query); |
| 106 this->validate(); | 115 this->validate(); |
| 107 SkASSERT(0 == fDeferredInserts.count()); // If this fails, you should have
flushed. | 116 SkASSERT(0 == fDeferredInserts.count()); // If this fails, you should have
flushed. |
| 108 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query
)) { | 117 if (!this->isEmpty() && SkIRect::IntersectsNoEmptyCheck(fRoot.fBounds, query
)) { |
| 109 this->search(fRoot.fChild.subtree, query, results); | 118 this->search(fRoot.fChild.subtree, query, results); |
| 110 } | 119 } |
| 111 this->validate(); | 120 this->validate(); |
| 112 } | 121 } |
| 113 | 122 |
| 114 void SkRTree::clear() { | 123 void SkRTree::clear() { |
| 115 this->validate(); | 124 this->validate(); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 480 |
| 472 // Expand 'out' to include 'joinWith' | 481 // Expand 'out' to include 'joinWith' |
| 473 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { | 482 static inline void join_no_empty_check(const SkIRect& joinWith, SkIRect* out) { |
| 474 // since we check for empty bounds on insert, we know we'll never have empty
rects | 483 // since we check for empty bounds on insert, we know we'll never have empty
rects |
| 475 // and we can save the empty check that SkIRect::join requires | 484 // and we can save the empty check that SkIRect::join requires |
| 476 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } | 485 if (joinWith.fLeft < out->fLeft) { out->fLeft = joinWith.fLeft; } |
| 477 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } | 486 if (joinWith.fTop < out->fTop) { out->fTop = joinWith.fTop; } |
| 478 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } | 487 if (joinWith.fRight > out->fRight) { out->fRight = joinWith.fRight; } |
| 479 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } | 488 if (joinWith.fBottom > out->fBottom) { out->fBottom = joinWith.fBottom; } |
| 480 } | 489 } |
| OLD | NEW |