Changeset 2190
- Timestamp:
- 01/30/08 00:05:46 (8 months ago)
- Files:
-
- gaphas/trunk/gaphas/quadtree.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/gaphas/quadtree.py
r2172 r2190 11 11 common features: 12 12 13 * They decompose space into adaptable cells 13 * They decompose space into adaptable cells. 14 14 * Each cell (or bucket) has a maximum capacity. 15 When maximum capacity is reached, the bucket splits 16 * The tree directory follows the spatial decomposition of the Quadtree 15 When maximum capacity is reached, the bucket splits. 16 * The tree directory follows the spatial decomposition of the Quadtree. 17 17 18 18 (From Wikipedia, the free encyclopedia) … … 84 84 85 85 def __init__(self, bounds=(0, 0, 0, 0), capacity=10): 86 """ 87 Create a new Quadtree instance. 88 89 Bounds is the boundries of the quadtree. this is fixed and do not 90 change depending on the contents. 91 92 Capacity defines the number of elements in one tree bucket (default: 10) 93 """ 86 94 self._capacity = capacity 87 95 self._bucket = QuadtreeBucket(bounds, capacity) … … 95 103 96 104 def resize(self, bounds): 105 """ 106 Resize the tree. 107 The tree structure is rebuild. 108 """ 97 109 self._bucket = QuadtreeBucket(bounds, self._capacity) 98 110 self.rebuild() … … 101 113 def get_soft_bounds(self): 102 114 """ 103 Calculate the size of all items in the Quadtree. This size may be beyond 104 the limits of the quadtree itself 115 Calculate the size of all items in the tree. This size may be beyond 116 the limits of the tree itself. 117 118 Returns a tuple (x, y, width, height). 119 105 120 >>> qtree = Quadtree() 106 121 >>> qtree.add('1', (10, 20, 30, 40)) … … 169 184 def rebuild(self): 170 185 """ 171 Rebuild the Quadtree structure.186 Rebuild the tree structure. 172 187 """ 173 188 # Clean bucket and items: … … 189 204 190 205 def get_data(self, item): 206 """ 207 Return the data for the given item, None if no data was provided. 208 """ 191 209 return self._ids[item][1] 192 210 193 211 194 212 def get_clipped_bounds(self, item): 213 """ 214 Return the bounding box for the given item. The bounding box is clipped 215 on the boundries of the tree (provided on construction or with 216 resize()). 217 """ 195 218 return self._ids[item][2] 196 219
