MCPcopy Index your code
hub / github.com/OmkarPathak/pygorithm / retrieve_collidables

Method retrieve_collidables

pygorithm/data_structures/quadtree.py:301–333  ·  view source on GitHub ↗

Find all entities that could collide with the specified entity. .. warning:: If entity is, itself, in the quadtree, it will be returned. The predicate may be used to prevent this using your preferred equality method.

(self, entity, predicate = None)

Source from the content-addressed store, hash-verified

299 self.children[quad].insert_and_think(entity)
300
301 def retrieve_collidables(self, entity, predicate = None):
302 """
303 Find all entities that could collide with the specified entity.
304
305 .. warning::
306
307 If entity is, itself, in the quadtree, it will be returned. The
308 predicate may be used to prevent this using your preferred equality
309 method.
310
311 The predicate takes 1 positional argument (the entity being considered)
312 and returns `False` if the entity should never be returned, even if it
313 might collide with the entity. It should return `True` otherwise.
314
315 :param entity: the entity to find collidables for
316 :type entity: :class:`.QuadTreeEntity`
317 :param predicate: the predicate
318 :type predicate: :class:`types.FunctionType` or None
319 :returns: potential collidables (never `None)
320 :rtype: list of :class:`.QuadTreeEntity`
321 """
322 result = list(filter(predicate, self.entities))
323 quadrant = self.get_quadrant(entity) if self.children else -1
324
325 if quadrant >= 0:
326 result.extend(self.children[quadrant].retrieve_collidables(entity, predicate))
327 elif self.children:
328 for child in self.children:
329 touching, overlapping, alwaysNone = rect2.Rect2.find_intersection(entity.aabb, child.location, find_mtv=False)
330 if touching or overlapping:
331 result.extend(child.retrieve_collidables(entity, predicate))
332
333 return result
334
335 def _iter_helper(self, pred):
336 """

Callers 1

test_retrieveMethod · 0.95

Calls 2

get_quadrantMethod · 0.95
find_intersectionMethod · 0.45

Tested by 1

test_retrieveMethod · 0.76