2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkQuadTree_DEFINED
9 #define SkQuadTree_DEFINED
12 #include "SkTDArray.h"
13 #include "SkBBoxHierarchy.h"
16 * An QuadTree implementation. In short, it is a tree containing a hierarchy of bounding rectangles
17 * in which each internal node has exactly four children.
19 * For more details see:
21 * http://en.wikipedia.org/wiki/Quadtree
23 class SkQuadTree : public SkBBoxHierarchy {
25 SK_DECLARE_INST_COUNT(SkQuadTree)
28 * Create a new QuadTree
30 static SkQuadTree* Create(const SkIRect& bounds);
31 virtual ~SkQuadTree();
34 * Insert a node, consisting of bounds and a data value into the tree, if we don't immediately
35 * need to use the tree; we may allow the insert to be deferred (this can allow us to bulk-load
36 * a large batch of nodes at once, which tends to be faster and produce a better tree).
37 * @param data The data value
38 * @param bounds The corresponding bounding box
39 * @param defer Can this insert be deferred? (this may be ignored)
41 virtual void insert(void* data, const SkIRect& bounds, bool defer = false) SK_OVERRIDE;
44 * If any inserts have been deferred, this will add them into the tree
46 virtual void flushDeferredInserts() SK_OVERRIDE {}
49 * Given a query rectangle, populates the passed-in array with the elements it intersects
51 virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
53 virtual void clear() SK_OVERRIDE;
56 * Gets the depth of the tree structure
58 virtual int getDepth() const SK_OVERRIDE;
61 * This gets the insertion count (rather than the node count)
63 virtual int getCount() const SK_OVERRIDE { return fCount; }
65 virtual void rewindInserts() SK_OVERRIDE;
70 SkQuadTree(const SkIRect& bounds);
72 // This is the count of data elements (rather than total nodes in the tree)
77 typedef SkBBoxHierarchy INHERITED;