Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Unified Diff: src/core/SkQuadTree.h

Issue 131343011: Initial QuadTree implementation (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed comments Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkQuadTree.h
diff --git a/src/core/SkQuadTree.h b/src/core/SkQuadTree.h
new file mode 100644
index 0000000000000000000000000000000000000000..0bb03b6514e2c9a9a82da0a1751f186c4dc78889
--- /dev/null
+++ b/src/core/SkQuadTree.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkQuadTree_DEFINED
+#define SkQuadTree_DEFINED
+
+#include "SkRect.h"
+#include "SkTDArray.h"
+#include "SkBBoxHierarchy.h"
+
+/**
+ * An QuadTree implementation. In short, it is a tree containing a hierarchy of bounding rectangles
+ * in which each internal node has exactly four children.
+ *
+ * For more details see:
+ *
+ * http://en.wikipedia.org/wiki/Quadtree
+ */
+class SkQuadTree : public SkBBoxHierarchy {
+public:
+ SK_DECLARE_INST_COUNT(SkQuadTree)
+
+ /**
+ * Create a new QuadTree
+ */
+ static SkQuadTree* Create(const SkIRect& bounds);
+ virtual ~SkQuadTree();
+
+ /**
+ * Insert a node, consisting of bounds and a data value into the tree, if we don't immediately
+ * need to use the tree; we may allow the insert to be deferred (this can allow us to bulk-load
+ * a large batch of nodes at once, which tends to be faster and produce a better tree).
+ * @param data The data value
+ * @param bounds The corresponding bounding box
+ * @param defer Can this insert be deferred? (this may be ignored)
+ */
+ virtual void insert(void* data, const SkIRect& bounds, bool defer = false) SK_OVERRIDE;
+
+ /**
+ * If any inserts have been deferred, this will add them into the tree
+ */
+ virtual void flushDeferredInserts() SK_OVERRIDE {}
+
+ /**
+ * Given a query rectangle, populates the passed-in array with the elements it intersects
+ */
+ virtual void search(const SkIRect& query, SkTDArray<void*>* results) SK_OVERRIDE;
+
+ virtual void clear() SK_OVERRIDE;
+
+ /**
+ * Gets the depth of the tree structure
+ */
+ virtual int getDepth() const SK_OVERRIDE;
+
+ /**
+ * This gets the insertion count (rather than the node count)
+ */
+ virtual int getCount() const SK_OVERRIDE { return fCount; }
+
+ virtual void rewindInserts() SK_OVERRIDE;
+
+private:
+
+ class QuadTreeNode;
+ struct Data {
Stephen White 2014/01/29 16:14:59 Nit: is it necessary to declare this in the header
sugoi1 2014/01/29 16:18:51 Done. You're right, it was used in my initial impl
+ Data(const SkIRect& bounds, void* data) : fBounds(bounds), fInnerBounds(bounds), fData(data) {}
+ SkIRect fBounds;
+ SkIRect fInnerBounds;
+ void* fData;
+ };
+
+ SkQuadTree(const SkIRect& bounds);
+
+ // This is the count of data elements (rather than total nodes in the tree)
+ int fCount;
+
+ QuadTreeNode* fRoot;
sugoi1 2014/01/29 15:29:08 Renamed fQuadTree to fRoot, since it is effectivel
+
+ typedef SkBBoxHierarchy INHERITED;
+};
+
+#endif
« no previous file with comments | « src/core/SkBBoxHierarchy.h ('k') | src/core/SkQuadTree.cpp » ('j') | src/core/SkQuadTree.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698