gummworld2.spatialhash (version $Id: spatialhash.py 414 2013-08-19 05:19:47Z stabbingfinger@gmail.com $)
index
c:\cygwin\home\bw\devel\python\svn\gummworld2_devel\gamelib\gummworld2\spatialhash.py

spatialhash.py - High performance spatial hash for spatial
partitioning and fast collision detection.
 
Objects (other than geometry.LineGeometry) must have a pygame Rect attribute.
Optionally, objects may have a collided static method attribute for lower-level
collision detection (see the gummworld2.geometry module).
 
Objects that are outside the world bounding rect are ignored by add().
 
This module is derived from the article and source code written by Conkerjo at
http://conkerjo.wordpress.com/2009/06/13/spatial-hashing-implementation-for-fast-2d-collisions/.

 
Modules
       
gummworld2.geometry
pygame
time

 
Classes
       
__builtin__.object
SpatialHash

 
class SpatialHash(__builtin__.object)
     Methods defined here:
__contains__(self, obj)
__init__(self, world_rect, cell_size)
__iter__(self)
__len__(self)
__str__(self)
add(self, obj)
Add or re-add obj. Return True if in bounds, else return False.
 
If this method returns False then the object is completely out of
bounds and cannot be stored in this space.
 
Note that when obj changes its position, you must add it again so that
its cell membership is updated. This method first removes the object if
it is already in the spatial hash.
clear(self)
Clear all objects.
collide(self, obj)
Return list of objects that collide with obj.
collidealldict(self, rect=None)
Return dict of all collisions.
 
If rect is specified, only the cells that intersect rect will be
checked.
 
The contents of the returned dict are: {obj : [other1,other2,...],...}
collideallflatlist(self, rect=None)
Return flat list of all collisions.
 
If rect is specified, only the cells that intersect rect will be
checked.
 
The contents of the returned list are: [obj1,other1,obj2,other2...]
collidealllist(self, rect=None)
Return list of all collisions.
 
If rect is specified, only the cells that intersect rect will be
checked.
 
The contents of the returned list are: [(obj,other),...]
collideany(self, obj)
Return True if obj collides with any other object, else False.
get_cell(self, cell_id)
Return the cell stored at bucket index cell_id.
 
The returned cell is a list of objects.
get_cell_grid(self, cell_id)
Return the (col,row) coordinate for cell id.
get_cell_pos(self, cell_id)
Return the world coordinates for topleft corner of cell.
get_nearby_objects(self, obj)
Return a list of objects that share the same cells as obj.
index(self, cell)
Return the bucket index of cell.
 
Returns None if cell does not exist in buckets.
 
Note that SpatialHash.buckets.index(cell) does *NOT* work because
list.index() tests equality, not identity.
index_at(self, x, y)
Return the cell_id of the cell that contains point (x,y).
 
None is returned if point (x,y) is not in bounds.
intersect_indices(self, rect)
Return list of cell ids that intersect rect.
intersect_objects(self, rect)
Return list of objects whose rects intersect rect.
itercells(self)
Returns a generator that iterates over all cells.
iterobjects(self)
Returns a generator that iterates over all objects.
 
Invoking a SpatialHash object as an iterator produces the same behavior
as iterobjects().
remove(self, obj)
Remove obj.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
objects
Return the entire list of objects.

 
Functions
       
ceil(...)
ceil(x)
 
Return the ceiling of x as a float.
This is the smallest integral value >= x.

 
Data
        __author__ = 'Gummbum, (c) 2011-2013'
__version__ = '$Id: spatialhash.py 414 2013-08-19 05:19:47Z stabbingfinger@gmail.com $'

 
Author
        Gummbum, (c) 2011-2013