collision: Docstring should not mention pyrex.
[python-bulletml.git] / bulletml / collision.py
index f185745..1683e58 100644 (file)
@@ -4,6 +4,10 @@ This module provides simple collision checking appropriate for
 shmups. It provides a routine to check whether two moving circles
 collided during the past frame.
 
 shmups. It provides a routine to check whether two moving circles
 collided during the past frame.
 
+An equivalent C-based version will be used automatically if it was
+compiled and installed with the module. If available, it will be noted
+in the docstrings for the functions.
+
 Basic Usage:
 
     from bulletml.collision import collides
 Basic Usage:
 
     from bulletml.collision import collides
@@ -20,6 +24,8 @@ def overlaps(a, b):
     Usually, you'll want to use the 'collides' method instead, but
     this one can be useful for just checking to see if the player has
     entered an area or hit a stationary oject.
     Usually, you'll want to use the 'collides' method instead, but
     this one can be useful for just checking to see if the player has
     entered an area or hit a stationary oject.
+
+    (This function is unoptimized.)
     """
 
     dx = a.x - b.x
     """
 
     dx = a.x - b.x
@@ -37,6 +43,8 @@ def collides(a, b):
     px, py - not required, defaults to x, y, previous frame position
     radius - not required, defaults to 0.5
 
     px, py - not required, defaults to x, y, previous frame position
     radius - not required, defaults to 0.5
 
+    (This function is unoptimized.)
+
     """
     # Current locations.
     xa = a.x
     """
     # Current locations.
     xa = a.x
@@ -79,3 +87,18 @@ def collides(a, b):
 
     # dist_sq < radius_sq
     return dist_x * dist_x + dist_y * dist_y <= radius * radius
 
     # dist_sq < radius_sq
     return dist_x * dist_x + dist_y * dist_y <= radius * radius
+
+def collides_all(a, others):
+    """Filter the second argument to those that collide with the first.
+
+    This is equivalent to filter(lambda o: collides(a, o), others),
+    but is much faster when the compiled extension is available (which
+    it is not currently).
+
+    """
+    return filter(lambda o: collides(a, o), others)
+
+try:
+    from bulletml._collision import collides, overlaps, collides_all
+except ImportError:
+    pass