18 std::vector<Branch> branches;
21 for (
int i = 0;
i <
N;
i++) {
30 branches.push_back(
b);
33 fCount = (
int)branches.size();
37 Node* n = this->allocateNodeAtLevel(0);
39 n->fChildren[0] = branches[0];
41 fRoot.fBounds = branches[0].fBounds;
43 fNodes.reserve(CountNodes(fCount));
44 fRoot = this->bulkLoad(&branches);
49SkRTree::Node* SkRTree::allocateNodeAtLevel(uint16_t
level) {
51 fNodes.push_back(
Node{});
60int SkRTree::CountNodes(
int branches) {
72 int currentBranch = 0;
74 while (currentBranch < branches) {
78 incrementBy -= remainder;
87 for (
int k = 1; k < incrementBy && currentBranch < branches; ++k) {
91 return nodes + CountNodes(nodes);
94SkRTree::Branch SkRTree::bulkLoad(std::vector<Branch>* branches,
int level) {
95 if (branches->size() == 1) {
96 return (*branches)[0];
114 int currentBranch = 0;
115 while (currentBranch < (
int)branches->size()) {
117 if (remainder != 0) {
120 incrementBy -= remainder;
129 n->fChildren[0] = (*branches)[currentBranch];
131 b.fBounds = (*branches)[currentBranch].fBounds;
134 for (
int k = 1; k < incrementBy && currentBranch < (
int)branches->size(); ++k) {
135 b.fBounds.join((*branches)[currentBranch].fBounds);
136 n->fChildren[k] = (*branches)[currentBranch];
140 (*branches)[newBranches] =
b;
143 branches->resize(newBranches);
144 return this->bulkLoad(branches,
level + 1);
148 if (fCount > 0 && SkRect::Intersects(fRoot.fBounds, query)) {
149 this->
search(fRoot.fSubtree, query, results);
154 for (
int i = 0;
i < node->fNumChildren; ++
i) {
155 if (SkRect::Intersects(node->fChildren[
i].fBounds, query)) {
156 if (0 == node->fLevel) {
157 results->push_back(node->fChildren[
i].fOpIndex);
159 this->
search(node->fChildren[
i].fSubtree, query, results);
166 size_t byteCount =
sizeof(
SkRTree);
168 byteCount += fNodes.capacity() *
sizeof(Node);
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
void insert(const SkRect[], int N) override
static const int kMinChildren
void search(const SkRect &query, std::vector< int > *results) const override
static const int kMaxChildren
size_t bytesUsed() const override
Optional< SkRect > bounds