Sum the number of entities in this quad tree and all lower quad trees. If `entities_per_depth` is not None, that array is used to calculate the sum of entities rather than traversing the tree. Either way, this is implemented iteratively. See :py:meth:`.__st
(self, entities_per_depth=None)
| 386 | return nodes_per_depth |
| 387 | |
| 388 | def sum_entities(self, entities_per_depth=None): |
| 389 | """ |
| 390 | Sum the number of entities in this quad tree and all lower quad trees. |
| 391 | |
| 392 | If `entities_per_depth` is not None, that array is used to calculate the sum |
| 393 | of entities rather than traversing the tree. Either way, this is implemented |
| 394 | iteratively. See :py:meth:`.__str__` for usage example. |
| 395 | |
| 396 | :param entities_per_depth: the result of :py:meth:`.find_entities_per_depth` |
| 397 | :type entities_per_depth: `dict int: (int, int)` or None |
| 398 | :returns: number of entities in this and child nodes |
| 399 | :rtype: int |
| 400 | """ |
| 401 | if entities_per_depth is not None: |
| 402 | return sum(entities_per_depth.values()) |
| 403 | |
| 404 | container = { 'result': 0 } |
| 405 | def handler(curr, container=container): |
| 406 | container['result'] += len(curr.entities) |
| 407 | self._iter_helper(handler) |
| 408 | |
| 409 | return container['result'] |
| 410 | |
| 411 | def calculate_avg_ents_per_leaf(self): |
| 412 | """ |