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

Unified Diff: cc/base/rtree.h

Issue 2881063003: cc: Change RTree::Search to return results, add comments, more tests. (Closed)
Patch Set: update Created 3 years, 7 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
« no previous file with comments | « no previous file | cc/base/rtree.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/rtree.h
diff --git a/cc/base/rtree.h b/cc/base/rtree.h
index 679bc84516ae982be750a894bf75d01f239f00b7..3d4d742c93e049cb20cdfe0e4f49fc63829e3476 100644
--- a/cc/base/rtree.h
+++ b/cc/base/rtree.h
@@ -40,6 +40,16 @@ class CC_BASE_EXPORT RTree {
RTree();
~RTree();
+ // Constructs the rtree from a given container of gfx::Rects. Queries using
+ // Search will then return indices into this container.
+ template <typename Container>
+ void Build(const Container& items) {
+ Build(items, [](const gfx::Rect& bounds) { return bounds; });
+ }
+
+ // Build helper that takes a container and a function used to get gfx::Rect
+ // from each item. That is, "bounds_getter(items[i]);" should return a
+ // gfx::Rect representing the bounds of items[i] for each i.
template <typename Container, typename Functor>
void Build(const Container& items, const Functor& bounds_getter) {
DCHECK_EQ(0u, num_data_elements_);
@@ -86,13 +96,11 @@ class CC_BASE_EXPORT RTree {
static_cast<size_t>(kMinChildren));
}
- template <typename Container>
- void Build(const Container& items) {
- Build(items, [](const gfx::Rect& bounds) { return bounds; });
- }
-
- void Search(const gfx::Rect& query, std::vector<size_t>* results) const;
+ // Given a query rect, returns sorted indices of elements that were used to
+ // construct this rtree.
+ std::vector<size_t> Search(const gfx::Rect& query) const;
+ // Returns the total bounds of all items in this rtree.
gfx::Rect GetBounds() const;
private:
« no previous file with comments | « no previous file | cc/base/rtree.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698