spatial_hashmap

class SpatialHashMap(cell_size: int = 8)

Implementation of a SpatialDataStructure using a hash-map. Accellerates spatial queries of EntityCollection.

add(item: SpatialLike) None

Add a SpatialLike instance to the SpatialHashMap.

Param:

The object to add.

clear() None

Deletes all entries in the structure.

get_all_entities() list[SpatialLike]

Get all the entities in the hash map. Iterates over every cell and returns the contents sequentially. Useful if you want to get all the Entities in a Blueprint without including structural ones like Groups.

Returns:

A list of all entities inside the hash map.

get_in_area(area: AABB, limit: int | None = None) list[SpatialLike]

Get all the entities whose collision_box overlaps an area.

Parameters:
  • area – The area to examine; specified in the format [[float, float], [float, float]].

  • limit – A maximum amount of entities to return.

Returns:

A list of all entities that intersect the area. Can be empty.

get_in_radius(radius: float, point: Sequence[float], limit: int | None = None) list[SpatialLike]

Get all the entities whose collision_set overlaps a circle.

Parameters:
  • radius – The radius of the circle.

  • pos – The center of the circle; Can be specified as a sequence or as a dict with "x" and "y" keys.

  • limit – A maximum amount of entities to return.

Returns:

A list of all entities that intersect the region. Can be empty.

get_on_point(point: utils.Point, limit: int = None) list[SpatialLike]

Get all the entities whose collision_set overlaps a point.

Parameters:
  • point – The position to examine; Can be specified as a PrimitiveVector or Vector.

  • limit – A maximum amount of entities to return.

Returns:

A list of all entities that intersect the point. Can be empty.

handle_overlapping(item: SpatialLike, merge: bool) None

Handles overlapping items if item were to be added to this hashmap. Issues overlapping objects warnings and merges entities if desired.

Warning

This function may not be permanent, or it may move somewhere else in future versions.

recursive_add(item: SpatialLike) None

Add the leaf-most entities to the hashmap.

This is used for Groups and other EntityCollections, where you need to add the Group’s children to the hashmap instead of the Group itself. Works with as many nested Groups as desired.

Parameters:

item – The object to add, or its children (if it has any).

recursive_remove(item: SpatialLike) None

Inverse of recursive_add().

Parameters:

item – The object to remove, or its children (if it has any).

remove(item: SpatialLike) None

Remove the SpatialLike instance from the SpatialHashMap.

Parameters:

item – The object to remove.