Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_GFX_GEOMETRY_R_TREE_H_ | 5 #ifndef UI_GFX_GEOMETRY_R_TREE_H_ |
| 6 #define UI_GFX_GEOMETRY_R_TREE_H_ | 6 #define UI_GFX_GEOMETRY_R_TREE_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
| 15 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 16 #include "ui/gfx/gfx_export.h" | 16 #include "ui/gfx/gfx_export.h" |
| 17 | 17 |
| 18 namespace gfx { | 18 namespace gfx { |
| 19 | 19 |
| 20 // Defines a heirarchical bounding rectangle data structure for Rect objects, | 20 // Defines a heirarchical bounding rectangle data structure for Rect objects, |
| 21 // associated with a generic unique key K for efficient spatial queries. The | 21 // associated with a generic unique key K for efficient spatial queries. The |
| 22 // R*-tree algorithm is used to build the trees. Based on the papers: | 22 // R*-tree algorithm is used to build the trees. Based on the papers: |
|
Peter Kasting
2014/05/02 18:04:57
Note: Since I am unfamiliar with these papers, exp
luken
2014/05/08 00:00:08
I guess I had assumed that people who were plannin
Peter Kasting
2014/05/08 18:08:21
It's a judgment call. The line I would try to dra
luken
2014/05/14 00:12:04
I think it's a good idea to try and describe these
| |
| 23 // | 23 // |
| 24 // A Guttman 'R-trees: a dynamic index structure for spatial searching', Proc | 24 // A Guttman 'R-trees: a dynamic index structure for spatial searching', Proc |
| 25 // ACM SIGMOD Int Conf on Management of Data, 47-57, 1984 | 25 // ACM SIGMOD Int Conf on Management of Data, 47-57, 1984 |
| 26 // | 26 // |
| 27 // N Beckmann, H-P Kriegel, R Schneider, B Seeger 'The R*-tree: an efficient and | 27 // N Beckmann, H-P Kriegel, R Schneider, B Seeger 'The R*-tree: an efficient and |
| 28 // robust access method for points and rectangles', Proc ACM SIGMOD Int Conf on | 28 // robust access method for points and rectangles', Proc ACM SIGMOD Int Conf on |
| 29 // Management of Data, 322-331, 1990 | 29 // Management of Data, 322-331, 1990 |
| 30 // | |
|
Peter Kasting
2014/04/30 23:09:21
Nit: Adding a blank comment line here seems slight
luken
2014/04/30 23:20:18
Yeah, I needed to change something to include this
Peter Kasting
2014/05/02 18:04:57
Cool, no worries.
luken
2014/05/08 00:00:08
Removed the blank comment line.
| |
| 30 class GFX_EXPORT RTree { | 31 class GFX_EXPORT RTree { |
| 31 public: | 32 public: |
| 32 RTree(size_t min_children, size_t max_children); | 33 RTree(size_t min_children, size_t max_children); |
| 33 ~RTree(); | 34 ~RTree(); |
| 34 | 35 |
| 35 // Insert a new rect into the tree, associated with provided key. Note that if | 36 // Insert a new rect into the tree, associated with provided key. Note that if |
| 36 // rect is empty, this rect will not actually be inserted. Duplicate keys | 37 // rect is empty, this rect will not actually be inserted. Duplicate keys |
| 37 // overwrite old entries. | 38 // overwrite old entries. |
| 38 void Insert(const Rect& rect, intptr_t key); | 39 void Insert(const Rect& rect, intptr_t key); |
| 39 | 40 |
| 40 // If present, remove the supplied key from the tree. | 41 // If present, remove the supplied key from the tree. |
| 41 void Remove(intptr_t key); | 42 void Remove(intptr_t key); |
| 42 | 43 |
| 43 // Fills a supplied list matches_out with all keys having bounding rects | 44 // Fills a supplied list matches_out with all keys having bounding rects |
| 44 // intersecting query_rect. | 45 // intersecting query_rect. |
| 45 void Query(const Rect& query_rect, | 46 void Query(const Rect& query_rect, |
| 46 base::hash_set<intptr_t>* matches_out) const; | 47 base::hash_set<intptr_t>* matches_out) const; |
| 47 | 48 |
| 48 // Removes all objects from the tree. | 49 // Removes all objects from the tree. |
| 49 void Clear(); | 50 void Clear(); |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 // Private data structure class for storing internal nodes or leaves with keys | 53 // Private data structure class for storing internal nodes or leaves with keys |
| 53 // of R-Trees. Note that "leaf" nodes can still have children, the children | 54 // of R-Trees. Note that "leaf" nodes can still have children, the children |
| 54 // will all be Nodes with non-NULL record pointers. | 55 // will all be Nodes with non-NULL record pointers. |
|
Peter Kasting
2014/05/02 18:04:57
Why call things leaves when they're technically no
luken
2014/05/08 00:00:08
Calling the nodes that only have "record node" chi
Peter Kasting
2014/05/08 18:08:21
You're in a better position to do this design than
luken
2014/05/14 00:12:04
Done.
| |
| 55 class GFX_EXPORT Node { | 56 class GFX_EXPORT Node { |
|
Peter Kasting
2014/05/02 18:04:57
From http://google-styleguide.googlecode.com/svn/t
luken
2014/05/08 00:00:08
I agree it would be cleaner and clearer to move th
| |
| 56 public: | 57 public: |
| 57 // Level counts from -1 for "record" Nodes, that is Nodes that wrap key | 58 // Level counts from -1 for "record" Nodes, that is Nodes that wrap key |
| 58 // values, to 0 for leaf Nodes, that is Nodes that only have record | 59 // values, to 0 for leaf Nodes, that is Nodes that only have record |
| 59 // children, up to the root Node, which has level equal to the height of the | 60 // children, up to the root Node, which has level equal to the height of the |
| 60 // tree. | 61 // tree. |
|
Peter Kasting
2014/05/02 18:04:57
I assume this means that all branches of the tree
luken
2014/05/08 00:00:08
Your assumption is correct. I made it explicit in
| |
| 61 explicit Node(int level); | 62 explicit Node(int level); |
|
Peter Kasting
2014/05/02 18:04:57
It seems strange that this API allows one to const
luken
2014/05/08 00:00:08
I've made this constructor only for level 0 nodes,
| |
| 62 | 63 |
| 63 // Builds a new record Node. | 64 // Builds a new record Node. |
| 64 Node(const Rect& rect, intptr_t key); | 65 Node(const Rect& rect, intptr_t key); |
|
Peter Kasting
2014/05/02 18:04:57
It's a bit surprising that the key type is intptr_
luken
2014/05/08 00:00:08
So the R-Tree CL was originally spun out from anot
Peter Kasting
2014/05/08 18:08:21
What were the concerns about the generic implement
luken
2014/05/14 00:12:04
By splitting the Node class into Record and Node c
| |
| 65 | 66 |
| 66 virtual ~Node(); | 67 virtual ~Node(); |
| 67 | 68 |
| 68 // Deletes all children and any attached record. | 69 // Deletes all children and any attached record. |
| 69 void Clear(); | 70 void Clear(); |
|
Peter Kasting
2014/05/02 18:04:57
Why is this method necessary? It seems to be call
luken
2014/05/08 00:00:08
Agreed, removed.
| |
| 70 | 71 |
| 71 // Recursive call to build a list of rects that intersect the query_rect. | 72 // Recursive call to build a list of rects that intersect the query_rect. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: list -> set; rects -> rects within this subtr
luken
2014/05/08 00:00:08
Ah, I thought it was only for member variables. I
| |
| 72 void Query(const Rect& query_rect, | 73 void Query(const Rect& query_rect, |
| 73 base::hash_set<intptr_t>* matches_out) const; | 74 base::hash_set<intptr_t>* matches_out) const; |
|
Peter Kasting
2014/05/02 18:04:57
Consider a typedef for "base::hash_set<intptr_t>".
luken
2014/05/08 00:00:08
Done.
| |
| 74 | 75 |
| 75 // Recompute our bounds by taking the union of all children rects. Will then | 76 // Recompute our bounds by taking the union of all children rects. Will then |
| 76 // call RecomputeBounds() on our parent for recursive bounds recalculation | 77 // call RecomputeBounds() on our parent for recursive bounds recalculation |
| 77 // up to the root. | 78 // up to the root. |
| 78 void RecomputeBounds(); | 79 void RecomputeBounds(); |
|
Peter Kasting
2014/05/02 18:04:57
It's a bit odd that calling RecomputeBounds() also
luken
2014/05/08 00:00:08
This is a side effect of the way that the algorith
Peter Kasting
2014/05/08 18:08:21
I think my thought was that the caller should, aft
luken
2014/05/14 00:12:04
Done.
| |
| 79 | 80 |
| 80 // Removes number_to_remove nodes from this Node, and appends them to the | 81 // Removes number_to_remove nodes from this Node, and appends them to the |
| 81 // supplied list. Does not repair bounds upon completion. | 82 // supplied list. Does not repair bounds upon completion. |
|
Peter Kasting
2014/05/02 18:04:57
Removes these nodes how? I assume you mean child
luken
2014/05/08 00:00:08
Done.
| |
| 82 void RemoveNodesForReinsert(size_t number_to_remove, | 83 void RemoveNodesForReinsert(size_t number_to_remove, |
|
Peter Kasting
2014/05/02 18:04:57
Since the function name says "ForReinsert", consid
luken
2014/05/08 00:00:08
Done.
| |
| 83 ScopedVector<Node>* nodes); | 84 ScopedVector<Node>* nodes); |
| 84 | 85 |
| 85 // Given a pointer to a child node within this Node, remove it from our | 86 // Given a pointer to a child node within this Node, remove it from our |
|
Peter Kasting
2014/05/02 18:04:57
From http://google-styleguide.googlecode.com/svn/t
luken
2014/05/08 00:00:08
Done.
| |
| 86 // list. If that child had any children, append them to the supplied orphan | 87 // list. If that child had any children, append them to the supplied orphan |
| 87 // list. Returns the new count of this node after removal. Does not | 88 // list. Returns the new count of this node after removal. Does not |
|
Peter Kasting
2014/05/02 18:04:57
I assume we do not recurse, so the orphans may be
luken
2014/05/08 00:00:08
Yup.
| |
| 88 // recompute bounds, as this node itself may be removed if it now has too | 89 // recompute bounds, as this node itself may be removed if it now has too |
| 89 // few children. | 90 // few children. |
|
Peter Kasting
2014/05/02 18:04:57
This last sentence is confusing. It seems to be d
luken
2014/05/08 00:00:08
Done.
| |
| 90 size_t RemoveChild(Node* child_node, ScopedVector<Node>* orphans); | 91 size_t RemoveChild(Node* child_node, ScopedVector<Node>* orphans); |
| 91 | 92 |
| 92 // Does what it says on the tin. Returns NULL if no children. Does not | 93 // Does what it says on the tin. Returns NULL if no children. Does not |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Remove first sentence.
luken
2014/05/08 00:00:08
Done.
| |
| 93 // recompute bounds. | 94 // recompute bounds. |
| 94 scoped_ptr<Node> RemoveAndReturnLastChild(); | 95 scoped_ptr<Node> RemoveAndReturnLastChild(); |
| 95 | 96 |
| 96 // Given a node, returns the best fit node for insertion of that node at | 97 // Given a node, returns the best fit node for insertion of that node at |
| 97 // the nodes level(). | 98 // the nodes level(). |
|
Peter Kasting
2014/05/02 18:04:57
Nit: nodes -> node's
The comment here is somewhat
luken
2014/05/08 00:00:08
Reworded.
| |
| 98 Node* ChooseSubtree(Node* node); | 99 Node* ChooseSubtree(Node* node); |
| 99 | 100 |
| 100 // Adds the provided node to this Node. Returns the new count of records | 101 // Adds the provided node to this Node. Returns the new count of records |
|
Peter Kasting
2014/05/02 18:04:57
Nit: to -> as a child of
luken
2014/05/08 00:00:08
Done.
| |
| 101 // stored in the Node. Will recompute the bounds of this node after | 102 // stored in the Node. Will recompute the bounds of this node after |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Will recompute -> Recomputes (but better yet,
luken
2014/05/08 00:00:08
Done.
| |
| 102 // addition. | 103 // addition. |
| 103 size_t AddChild(Node* node); | 104 size_t AddChild(Node* node); |
|
Peter Kasting
2014/05/02 18:04:57
Is the caller passing in ownership? If not, who o
luken
2014/05/08 00:00:08
Done.
| |
| 104 | 105 |
| 105 // Returns a sibling to this Node with at least min_children and no greater | 106 // Returns a sibling to this Node with at least min_children and no greater |
| 106 // than max_children of this Node's children assigned to it, and having the | 107 // than max_children of this Node's children assigned to it, and having the |
| 107 // same parent. Bounds will be valid on both Nodes after this call. | 108 // same parent. Bounds will be valid on both Nodes after this call. |
| 108 Node* Split(size_t min_children, size_t max_children); | 109 Node* Split(size_t min_children, size_t max_children); |
| 109 | 110 |
| 110 // For record nodes only, to support re-insert, allows setting the rect. | 111 // For record nodes only, to support re-insert, allows setting the rect. |
| 111 void SetRect(const Rect& rect); | 112 void SetRect(const Rect& rect); |
| 112 | 113 |
| 113 // Returns a pointer to the parent of this Node, or NULL if no parent. | 114 // Returns a pointer to the parent of this Node, or NULL if no parent. |
| 114 Node* parent() const { return parent_; } | 115 Node* parent() const { return parent_; } |
|
Peter Kasting
2014/05/02 18:04:57
From http://google-styleguide.googlecode.com/svn/t
luken
2014/05/08 00:00:08
Done.
| |
| 115 | 116 |
| 116 // 0 level() would mean that this Node is a leaf. 1 would mean that this | 117 // 0 level() would mean that this Node is a leaf. 1 would mean that this |
| 117 // Node has children that are leaves. Calling level() on root_ returns the | 118 // Node has children that are leaves. Calling level() on root_ returns the |
| 118 // height of the tree - 1. A level of -1 means that this is a Record node. | 119 // height of the tree - 1. A level of -1 means that this is a Record node. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: These sorts of comments should go on the memb
luken
2014/05/08 00:00:08
Done.
| |
| 119 int level() const { return level_; } | 120 int level() const { return level_; } |
| 120 | 121 |
| 121 const Rect& rect() const { return rect_; } | 122 const Rect& rect() const { return rect_; } |
| 122 | 123 |
| 123 size_t count() const { return children_.size(); } | 124 size_t count() const { return children_.size(); } |
| 124 | 125 |
| 125 intptr_t key() const { return key_; } | 126 intptr_t key() const { return key_; } |
| 126 | 127 |
| 127 private: | 128 private: |
| 128 // Returns all records stored in this node and its children. | 129 // Returns all records stored in this node and its children. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Since records shouldn't ever be stored in bot
luken
2014/05/08 00:00:08
Done.
| |
| 129 void GetAllValues(base::hash_set<intptr_t>* matches_out) const; | 130 void GetAllValues(base::hash_set<intptr_t>* matches_out) const; |
| 130 | 131 |
| 131 // Used for sorting Nodes along vertical and horizontal axes | 132 // Used for sorting Nodes along vertical and horizontal axes |
|
Peter Kasting
2014/05/02 18:04:57
From http://google-styleguide.googlecode.com/svn/t
luken
2014/05/08 00:00:08
Done.
| |
| 132 static bool CompareVertical(Node* a, Node* b); | 133 static bool CompareVertical(Node* a, Node* b); |
|
Peter Kasting
2014/05/02 18:04:57
Prefer file-scoped helper functions in the .cc fil
luken
2014/05/08 00:00:08
I have unit tests for all three, so needed to leav
| |
| 133 | 134 |
|
Peter Kasting
2014/05/02 18:04:57
Nit: If the comment above applies to both these fu
luken
2014/05/08 00:00:08
Done.
| |
| 134 static bool CompareHorizontal(Node* a, Node* b); | 135 static bool CompareHorizontal(Node* a, Node* b); |
| 135 | 136 |
| 136 static bool CompareCenterDistanceFromParent(Node* a, Node* b); | 137 static bool CompareCenterDistanceFromParent(Node* a, Node* b); |
| 137 | 138 |
| 138 // Returns the increase in overlap value, as defined in Beckmann et al as | 139 // Returns the increase in overlap value, as defined in Beckmann et al as |
|
Peter Kasting
2014/05/02 18:04:57
Super-tiny nit: et al as -> et al. as
luken
2014/05/08 00:00:08
Done.
| |
| 139 // the sum of the areas of the intersection of each |children_| rectangle | 140 // the sum of the areas of the intersection of each |children_| rectangle |
|
Peter Kasting
2014/05/02 18:04:57
Nit: each |children_| rectangle -> all child recta
luken
2014/05/08 00:00:08
Done.
| |
| 140 // (excepting the candidate child) with the argument rectangle. The | 141 // (excepting the candidate child) with the argument rectangle. The |
| 141 // expanded_rect argument is computed as the union of the candidate child | 142 // expanded_rect argument is computed as the union of the candidate child |
| 142 // rect and the argument rect, and is included here to avoid recomputation. | 143 // rect and the argument rect, and is included here to avoid recomputation. |
| 143 // Here the candidate child is indicated by index in |children_|, and | 144 // Here the candidate child is indicated by index in |children_|, and |
| 144 // expanded_rect is the alread-computed union of candidate's rect and | 145 // expanded_rect is the alread-computed union of candidate's rect and |
| 145 // rect. | 146 // rect. |
|
Peter Kasting
2014/05/02 18:04:57
You describe |expanded_rect| twice. Only describe
luken
2014/05/08 00:00:08
Yes, it can. Done.
| |
| 146 int OverlapIncreaseToAdd(const Rect& rect, | 147 int OverlapIncreaseToAdd(const Rect& rect, |
| 147 size_t candidate, | 148 size_t candidate, |
| 148 const Rect& expanded_rect); | 149 const Rect& expanded_rect); |
| 149 | 150 |
| 150 // Bounds recomputation without calling parents to do the same. | 151 // Bounds recomputation without calling parents to do the same. |
| 151 void RecomputeBoundsNoParents(); | 152 void RecomputeBoundsNoParents(); |
| 152 | 153 |
| 153 // Split() helper methods. | 154 // Split() helper methods. |
| 154 // | 155 // |
| 155 // Given two vectors of Nodes sorted by vertical or horizontal bounds, this | 156 // Given two vectors of Nodes sorted by vertical or horizontal bounds, this |
| 156 // function populates two vectors of Rectangles in which the ith element is | 157 // function populates two vectors of Rectangles in which the ith element is |
| 157 // the Union of all bounding rectangles [0,i] in the associated sorted array | 158 // the Union of all bounding rectangles [0,i] in the associated sorted array |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Capitalizing Union here and below is odd
luken
2014/05/08 00:00:08
Done.
| |
| 158 // of Nodes. | 159 // of Nodes. |
| 159 static void BuildLowBounds(const std::vector<Node*>& vertical_sort, | 160 static void BuildLowBounds(const std::vector<Node*>& vertical_sort, |
|
Peter Kasting
2014/05/02 18:04:57
Nit: It's not a rule, but I tend to prefer listing
luken
2014/05/08 00:00:08
Done.
| |
| 160 const std::vector<Node*>& horizontal_sort, | 161 const std::vector<Node*>& horizontal_sort, |
| 161 std::vector<Rect>* vertical_bounds, | 162 std::vector<Rect>* vertical_bounds, |
|
Peter Kasting
2014/05/02 18:04:57
Also consider a "typedef std::vector<Rect> Rects"
luken
2014/05/08 00:00:08
Done.
| |
| 162 std::vector<Rect>* horizontal_bounds); | 163 std::vector<Rect>* horizontal_bounds); |
| 163 | 164 |
| 164 // Given two vectors of Nodes sorted by vertical or horizontal bounds, this | 165 // Given two vectors of Nodes sorted by vertical or horizontal bounds, this |
| 165 // function populates two vectors of Rectangles in which the ith element is | 166 // function populates two vectors of Rectangles in which the ith element is |
| 166 // the Union of all bounding rectangles [i, count()) in the associated | 167 // the Union of all bounding rectangles [i, count()) in the associated |
| 167 // sorted array of Nodes. | 168 // sorted array of Nodes. |
| 168 static void BuildHighBounds(const std::vector<Node*>& vertical_sort, | 169 static void BuildHighBounds(const std::vector<Node*>& vertical_sort, |
| 169 const std::vector<Node*>& horizontal_sort, | 170 const std::vector<Node*>& horizontal_sort, |
| 170 std::vector<Rect>* vertical_bounds, | 171 std::vector<Rect>* vertical_bounds, |
| 171 std::vector<Rect>* horizontal_bounds); | 172 std::vector<Rect>* horizontal_bounds); |
| 172 | 173 |
| 173 // Returns true if this is a vertical split, false if a horizontal one. | 174 // Returns true if this is a vertical split, false if a horizontal one. |
| 174 // Based on ChooseSplitAxis algorithm in Beckmann et al. Chooses the axis | 175 // Based on ChooseSplitAxis algorithm in Beckmann et al. Chooses the axis |
| 175 // with the lowest sum of margin values of bounding boxes. | 176 // with the lowest sum of margin values of bounding boxes. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: It would be nice if this comment were just a
luken
2014/05/08 00:00:08
Done.
| |
| 176 static bool ChooseSplitAxis(const std::vector<Rect>& low_vertical_bounds, | 177 static bool ChooseSplitAxis(const std::vector<Rect>& low_vertical_bounds, |
| 177 const std::vector<Rect>& high_vertical_bounds, | 178 const std::vector<Rect>& high_vertical_bounds, |
| 178 const std::vector<Rect>& low_horizontal_bounds, | 179 const std::vector<Rect>& low_horizontal_bounds, |
| 179 const std::vector<Rect>& high_horizontal_bounds, | 180 const std::vector<Rect>& high_horizontal_bounds, |
| 180 size_t min_children, | 181 size_t min_children, |
| 181 size_t max_children); | 182 size_t max_children); |
| 182 | 183 |
| 183 // Used by SplitNode to calculate optimal index of split, after determining | 184 // Used by SplitNode to calculate optimal index of split, after determining |
|
Peter Kasting
2014/05/02 18:04:57
There doesn't seem to be a function called SplitNo
luken
2014/05/08 00:00:08
Split()'s old name. Fixed up the comment.
| |
| 184 // along which axis to sort and split the children rectangles. Returns the | 185 // along which axis to sort and split the children rectangles. Returns the |
| 185 // index to the first element in the split children as sorted by the bounds | 186 // index to the first element in the split children as sorted by the bounds |
| 186 // vectors. | 187 // vectors. |
| 187 static size_t ChooseSplitIndex(size_t min_children, | 188 static size_t ChooseSplitIndex(size_t min_children, |
| 188 size_t max_children, | 189 size_t max_children, |
| 189 const std::vector<Rect>& low_bounds, | 190 const std::vector<Rect>& low_bounds, |
| 190 const std::vector<Rect>& high_bounds); | 191 const std::vector<Rect>& high_bounds); |
| 191 | 192 |
| 192 // Takes our children_ and divides them into a new node, starting at index | 193 // Takes our children_ and divides them into a new node, starting at index |
| 193 // split_index in sorted_children. | 194 // split_index in sorted_children. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Your comment sort of says this already, but i
luken
2014/05/08 00:00:08
Done.
| |
| 194 Node* DivideChildren(const std::vector<Rect>& low_bounds, | 195 Node* DivideChildren(const std::vector<Rect>& low_bounds, |
| 195 const std::vector<Rect>& high_bounds, | 196 const std::vector<Rect>& high_bounds, |
| 196 const std::vector<Node*>& sorted_children, | 197 const std::vector<Node*>& sorted_children, |
| 197 size_t split_index); | 198 size_t split_index); |
| 198 | 199 |
| 199 // Returns a pointer to the child node that will result in the least overlap | 200 // Returns a pointer to the child node that will result in the least overlap |
| 200 // increase with the addition of node_rect, as defined in the Beckmann et al | 201 // increase with the addition of node_rect, as defined in the Beckmann et al |
| 201 // paper, or NULL if there's a tie found. Requires a precomputed vector of | 202 // paper, or NULL if there's a tie found. Requires a precomputed vector of |
|
Peter Kasting
2014/05/02 18:04:57
Again, this comment is relatively opaque to someon
luken
2014/05/08 00:00:08
Done.
| |
| 202 // expanded rectangles where the ith rectangle in the vector is the union of | 203 // expanded rectangles where the ith rectangle in the vector is the union of |
| 203 // |children_|[i] and node_rect. | 204 // |children_|[i] and node_rect. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: Once you have a full expression using a varia
luken
2014/05/08 00:00:08
Done.
| |
| 204 Node* LeastOverlapIncrease(const Rect& node_rect, | 205 Node* LeastOverlapIncrease(const Rect& node_rect, |
| 205 const std::vector<Rect>& expanded_rects); | 206 const std::vector<Rect>& expanded_rects); |
| 206 | 207 |
| 207 // Returns a pointer to the child node that will result in the least area | 208 // Returns a pointer to the child node that will result in the least area |
| 208 // enlargement if the argument node rectangle were to be added to that | 209 // enlargement if the argument node rectangle were to be added to that |
| 209 // nodes' bounding box. Requires a precomputed vector of expanded rectangles | 210 // nodes' bounding box. Requires a precomputed vector of expanded rectangles |
| 210 // where the ith rectangle in the vector is the union of |children_|[i] and | 211 // where the ith rectangle in the vector is the union of |children_|[i] and |
| 211 // node_rect. | 212 // node_rect. |
| 212 Node* LeastAreaEnlargement(const Rect& node_rect, | 213 Node* LeastAreaEnlargement(const Rect& node_rect, |
| 213 const std::vector<Rect>& expanded_rects); | 214 const std::vector<Rect>& expanded_rects); |
| 214 | 215 |
| 215 // This Node's bounding rectangle. | 216 // This Node's bounding rectangle. |
| 216 Rect rect_; | 217 Rect rect_; |
| 217 | 218 |
| 218 // The height of the node in the tree, counting from -1 at the record node | 219 // The height of the node in the tree, counting from -1 at the record node |
| 219 // to 0 at the leaf up to the root node which has level equal to the height | 220 // to 0 at the leaf up to the root node which has level equal to the height |
| 220 // of the tree. | 221 // of the tree. |
| 221 int level_; | 222 int level_; |
|
Peter Kasting
2014/05/02 18:04:57
From http://google-styleguide.googlecode.com/svn/t
luken
2014/05/08 00:00:08
Done.
| |
| 222 | 223 |
| 223 // Pointers to all of our children Nodes. | 224 // Pointers to all of our children Nodes. |
|
Peter Kasting
2014/05/02 18:04:57
Nit: children -> child
luken
2014/05/08 00:00:08
Done.
| |
| 224 ScopedVector<Node> children_; | 225 ScopedVector<Node> children_; |
|
Peter Kasting
2014/05/02 18:04:57
This is another place I suggest a typedef; it will
luken
2014/05/08 00:00:08
Done.
| |
| 225 | 226 |
| 226 // A weak pointer to our parent Node in the RTree. The root node will have a | 227 // A weak pointer to our parent Node in the RTree. The root node will have a |
| 227 // NULL value for |parent_|. | 228 // NULL value for |parent_|. |
| 228 Node* parent_; | 229 Node* parent_; |
| 229 | 230 |
| 230 // If this is a record Node, then |key_| will be non-NULL and will contain | 231 // If this is a record Node, then |key_| will be non-NULL and will contain |
| 231 // the key data. Otherwise, NULL. | 232 // the key data. Otherwise, NULL. |
|
Peter Kasting
2014/05/02 18:04:57
You refer to NULL here, but the code in the .cc fi
luken
2014/05/08 00:00:08
Yeah I'm not in love with it either. Perhaps movin
| |
| 232 intptr_t key_; | 233 intptr_t key_; |
| 233 | 234 |
| 234 friend class RTreeTest; | 235 friend class RTreeTest; |
| 235 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeBuildHighBounds); | 236 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeBuildHighBounds); |
|
Peter Kasting
2014/05/02 18:04:57
If you already declare RTreeTest a friend class, i
luken
2014/05/08 00:00:08
Well certainly possible to hoist value access, lik
Peter Kasting
2014/05/08 18:08:21
I believe you can do this via typedefs:
class RTr
luken
2014/05/14 00:12:04
Oh I didn't know that! Done.
| |
| 236 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeBuildLowBounds); | 237 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeBuildLowBounds); |
| 237 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeChooseSplitAxisAndIndex); | 238 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeChooseSplitAxisAndIndex); |
| 238 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeChooseSubtree); | 239 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeChooseSubtree); |
| 239 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareCenterDistanceFromParent); | 240 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareCenterDistanceFromParent); |
| 240 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareHorizontal); | 241 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareHorizontal); |
| 241 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareVertical); | 242 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeCompareVertical); |
| 242 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeDivideChildren); | 243 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeDivideChildren); |
| 243 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeLeastAreaEnlargement); | 244 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeLeastAreaEnlargement); |
| 244 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeLeastOverlapIncrease); | 245 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeLeastOverlapIncrease); |
| 245 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeOverlapIncreaseToAdd); | 246 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeOverlapIncreaseToAdd); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeRemoveChildOrphans); | 288 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeRemoveChildOrphans); |
| 288 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeRemoveNodesForReinsert); | 289 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeRemoveNodesForReinsert); |
| 289 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeSplit); | 290 FRIEND_TEST_ALL_PREFIXES(RTreeTest, NodeSplit); |
| 290 | 291 |
| 291 DISALLOW_COPY_AND_ASSIGN(RTree); | 292 DISALLOW_COPY_AND_ASSIGN(RTree); |
| 292 }; | 293 }; |
| 293 | 294 |
| 294 } // namespace gfx | 295 } // namespace gfx |
| 295 | 296 |
| 296 #endif // UI_GFX_GEOMETRY_R_TREE_H_ | 297 #endif // UI_GFX_GEOMETRY_R_TREE_H_ |
| OLD | NEW |