This module provides some functions for collision detection.
collide(objects) -> list of collisions
Collides objects, first using rdc() and then using brute_force().
Each object should have the attributes x, y, bounding_radius, and bounding_radius_squared.
collide_single(single, objects)
Finds collisions between a single object and a list of objects.
single can either be an object with x, y, and bounding_radius attributes, or a tuple of (x,y, bounding_radius) (In both cases, bounding_radius is optional and defaults to 0.)
collide_groups(group_a, group_b)
Returns a list of collisions between objects in group_a with objects in group_b.
All objects must either have x, y, and (optionally) bounding_radius attributes or behave like a tuple with the form (x, y, bounding_radius) or (x, y).
If bounding_radius is missing it will default to 0.
aabb_collide(objects)
aabb_collide works similar to collide, but instead of using bounding radius it uses axis aligned bounding boxes [AABB].
All objects must have left, top, right, and bottom attributes.
aabb_collide_single(single, objects)
Finds all objects in objects that collide with single, (using bounding boxes.)
All objects must have left, top, right, and bottom attributes.
A list of all objects from objects that collide with single is returned.
aabb_collide_groups(group_a, group_b)
Returns a list of collisions between objects in group_a with objects in group_b.
All objects must have left, top, right, and bottom attributes.
rdc(objects, [max_depth,] [min_split]) -> list of collision groups
Uses the Recursive Dimensional Clustering algorithm to find groups of colliding objects.
objects should be a list of objects. Each object should have the attributes x, y, and bounding_radius.
If the number of objects in a collision group is less than min_split, recursion will stop. This defaults to 1, but in practice, it is usually faster to just use a brute force method once a group gets down to 10 objects.
max_depth is the maximum number of recursions to make. It defaults to 0, which is infinite.
Instead of returning individual collisions, rdc() returns groups (lists) of colliding objects. For example, if A collides with B and B collides with C, one of the groups will be [A, B, C], even though A and C don't directly collide.
Also, each object is returned at most once. If it is in one group, it won't be in any other. An object without any collisions isn't returned at all.
brute_force(objects) -> list of collisions
Finds collisions between objects using a brute force algorithm.
objects should be a list of objects, each of which have the attributes x, y, and bounding_radius_squared. Each object is checked against every other object.
For example, if A collides with B, B collides with C, and D doesn't collide with anything, the result will be: [(A, B), (B, C)].