55 * found in the LICENSE file.
66 */
77
8- #include " skia/ platform_view_rtree.h"
8+ #include " platform_view_rtree.h"
99
1010PlatformViewRTree::PlatformViewRTree () : fCount(0 ) {}
1111
@@ -25,27 +25,23 @@ void PlatformViewRTree::insert(const SkRect boundsArray[],
2525 Branch b;
2626 b.fBounds = bounds;
2727 b.fOpIndex = i;
28+ b.isDraw = (metadata == nullptr ) ? false : metadata[i].isDraw ;
2829 branches.push_back (b);
2930 }
30- Branch b;
31- b.fBounds = bounds;
32- b.fOpIndex = i;
33- b.isDraw = (metadata == nullptr ) ? false : metadata[i].isDraw ;
34- branches.push_back (b);
35- }
3631
37- fCount = (int )branches.size();
38- if (fCount ) {
39- if (1 == fCount ) {
40- fNodes .reserve (1 );
41- Node* n = this ->allocateNodeAtLevel (0 );
42- n->fNumChildren = 1 ;
43- n->fChildren [0 ] = branches[0 ];
44- fRoot .fSubtree = n;
45- fRoot .fBounds = branches[0 ].fBounds ;
46- } else {
47- fNodes .reserve (CountNodes (fCount ));
48- fRoot = this ->bulkLoad (&branches);
32+ fCount = (int )branches.size ();
33+ if (fCount ) {
34+ if (1 == fCount ) {
35+ fNodes .reserve (1 );
36+ Node* n = this ->allocateNodeAtLevel (0 );
37+ n->fNumChildren = 1 ;
38+ n->fChildren [0 ] = branches[0 ];
39+ fRoot .fSubtree = n;
40+ fRoot .fBounds = branches[0 ].fBounds ;
41+ } else {
42+ fNodes .reserve (CountNodes (fCount ));
43+ fRoot = this ->bulkLoad (&branches);
44+ }
4945 }
5046}
5147
@@ -176,15 +172,17 @@ void PlatformViewRTree::search(Node* node, const SkRect& query, std::vector<int>
176172 }
177173}
178174
179- void PlatformViewRTree::searchRects (const SkRect& query, std::vector<SkRect*>* results) const {
175+ std::vector<SkRect> PlatformViewRTree::searchRects (const SkRect& query) const {
176+ std::vector<SkRect> results;
180177 if (fCount > 0 && SkRect::Intersects (fRoot .fBounds , query)) {
181178 this ->searchRects (fRoot .fSubtree , query, results);
182179 }
180+ return results;
183181}
184182
185183void PlatformViewRTree::searchRects (Node* node,
186184 const SkRect& query,
187- std::vector<SkRect*>* results) const {
185+ std::vector<SkRect>& results) const {
188186 if (!SkRect::Intersects (fRoot .fBounds , query)) {
189187 return ;
190188 }
@@ -201,38 +199,36 @@ void PlatformViewRTree::searchRects(Node* node,
201199 if (!node->fChildren [i].isDraw ) {
202200 continue ;
203201 }
204- SkRect* currentRecordRect = &node->fChildren [i].fBounds ;
205- std::vector<SkRect*> currentResults = *results;
202+ SkRect currentRecordRect = node->fChildren [i].fBounds ;
206203 bool replacedExistingRect = false ;
207- // If the current record rect intersects with any of the rects in the
208- // result vector, then join them, and update the rect in results.
209- size_t joiningRectIdx = currentResults .size ();
204+ // // If the current record rect intersects with any of the rects in the
205+ // // result vector, then join them, and update the rect in results.
206+ size_t joiningRectIdx = results .size ();
210207 size_t resultIdx = 0 ;
211- while (resultIdx < results-> size ()) {
212- if (SkRect::Intersects (*currentResults [resultIdx], * currentRecordRect)) {
208+ while (resultIdx < results. size ()) {
209+ if (SkRect::Intersects (results [resultIdx], currentRecordRect)) {
213210 joiningRectIdx = resultIdx;
214211 replacedExistingRect = true ;
215- currentResults [joiningRectIdx]-> join (* currentRecordRect);
212+ results [joiningRectIdx]. join (currentRecordRect);
216213 break ;
217214 }
218215 resultIdx++;
219216 }
220217 resultIdx = joiningRectIdx + 1 ;
221- // It's possible that after joining rects will result in duplicated
222- // rects in the results vector. For example, consider a result vector
223- // that contains rects A, B. If a new rect C is a superset of A and B,
224- // then A and B are the same set after the merge. As a result, find such
225- // cases and remove them from the result vector.
226- while (replacedExistingRect && resultIdx < results->size ()) {
227- if (SkRect::Intersects (*currentResults[resultIdx], *currentResults[joiningRectIdx])) {
228- currentResults[joiningRectIdx]->join (*currentResults[resultIdx]);
229- results->erase (results->begin () + resultIdx);
218+ // It's possible that the result contains duplicated rects at this point.
219+ // For example, consider a result vector that contains rects A, B. If a
220+ // new rect C is a superset of A and B, then A and B are the same set after
221+ // the merge. As a result, find such cases and remove them from the result vector.
222+ while (replacedExistingRect && resultIdx < results.size ()) {
223+ if (SkRect::Intersects (results[resultIdx], results[joiningRectIdx])) {
224+ results[joiningRectIdx].join (results[resultIdx]);
225+ results.erase (results.begin () + resultIdx);
230226 } else {
231227 resultIdx++;
232228 }
233229 }
234230 if (!replacedExistingRect) {
235- results-> push_back (currentRecordRect);
231+ results. push_back (currentRecordRect);
236232 }
237233 }
238234}
0 commit comments