Changeset 2190

Show
Ignore:
Timestamp:
01/30/08 00:05:46 (8 months ago)
Author:
arj..@yirdis.nl
Message:

Updated documentation of Quadtree class.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/trunk/gaphas/quadtree.py

    r2172 r2190  
    1111common features: 
    1212 
    13 * They decompose space into adaptable cells 
     13* They decompose space into adaptable cells. 
    1414* 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. 
    1717 
    1818(From Wikipedia, the free encyclopedia) 
     
    8484 
    8585    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        """ 
    8694        self._capacity = capacity 
    8795        self._bucket = QuadtreeBucket(bounds, capacity) 
     
    95103 
    96104    def resize(self, bounds): 
     105        """ 
     106        Resize the tree. 
     107        The tree structure is rebuild. 
     108        """ 
    97109        self._bucket = QuadtreeBucket(bounds, self._capacity) 
    98110        self.rebuild() 
     
    101113    def get_soft_bounds(self): 
    102114        """ 
    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 
    105120        >>> qtree = Quadtree() 
    106121        >>> qtree.add('1', (10, 20, 30, 40)) 
     
    169184    def rebuild(self): 
    170185        """ 
    171         Rebuild the Quadtree structure. 
     186        Rebuild the tree structure. 
    172187        """ 
    173188        # Clean bucket and items: 
     
    189204 
    190205    def get_data(self, item): 
     206        """ 
     207        Return the data for the given item, None if no data was provided. 
     208        """ 
    191209        return self._ids[item][1] 
    192210 
    193211 
    194212    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        """ 
    195218        return self._ids[item][2] 
    196219