OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/base/rtree.h" | 5 #include "cc/base/rtree.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 102 |
103 DCHECK_LT(new_branch_index, current_branch); | 103 DCHECK_LT(new_branch_index, current_branch); |
104 (*branches)[new_branch_index] = branch; | 104 (*branches)[new_branch_index] = branch; |
105 ++new_branch_index; | 105 ++new_branch_index; |
106 } | 106 } |
107 } | 107 } |
108 branches->resize(new_branch_index); | 108 branches->resize(new_branch_index); |
109 return BuildRecursive(branches, level + 1); | 109 return BuildRecursive(branches, level + 1); |
110 } | 110 } |
111 | 111 |
112 void RTree::Search(const gfx::Rect& query, std::vector<size_t>* results) const { | 112 std::vector<size_t> RTree::Search(const gfx::Rect& query) const { |
| 113 std::vector<size_t> results; |
113 if (num_data_elements_ > 0 && query.Intersects(root_.bounds)) | 114 if (num_data_elements_ > 0 && query.Intersects(root_.bounds)) |
114 SearchRecursive(root_.subtree, query, results); | 115 SearchRecursive(root_.subtree, query, &results); |
| 116 return results; |
115 } | 117 } |
116 | 118 |
117 void RTree::SearchRecursive(Node* node, | 119 void RTree::SearchRecursive(Node* node, |
118 const gfx::Rect& query, | 120 const gfx::Rect& query, |
119 std::vector<size_t>* results) const { | 121 std::vector<size_t>* results) const { |
120 for (uint16_t i = 0; i < node->num_children; ++i) { | 122 for (uint16_t i = 0; i < node->num_children; ++i) { |
121 if (query.Intersects(node->children[i].bounds)) { | 123 if (query.Intersects(node->children[i].bounds)) { |
122 if (node->level == 0) | 124 if (node->level == 0) |
123 results->push_back(node->children[i].index); | 125 results->push_back(node->children[i].index); |
124 else | 126 else |
125 SearchRecursive(node->children[i].subtree, query, results); | 127 SearchRecursive(node->children[i].subtree, query, results); |
126 } | 128 } |
127 } | 129 } |
128 } | 130 } |
129 | 131 |
130 gfx::Rect RTree::GetBounds() const { | 132 gfx::Rect RTree::GetBounds() const { |
131 return root_.bounds; | 133 return root_.bounds; |
132 } | 134 } |
133 | 135 |
134 } // namespace cc | 136 } // namespace cc |
OLD | NEW |