spatial_hashmap

class SpatialHashMap(cell_size: int = 4)

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

add(
item: SpatialLike,
merge: bool = False,
) SpatialLike | None

Add a SpatialLike instance to the SpatialDataStructure.

Parameters:
item: SpatialLike

The object to add.

merge: bool = False

Whether or not to attempt to merge the added item with any existing item, if possible.

Returns:

The input SpatialLike if properly added, or None if the input object was merged.

clear() None

Deletes all entries in the structure.

get_all() 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_aabb(
aabb: AABB,
limit: int | None = None,
) list[SpatialLike]

Get all the entities whose collision_set overlaps an AABB.

Parameters:
aabb: AABB

The AABB to examine.

limit: int | None = None

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: tuple[int | float, int | float],
limit: int | None = None,
) list[SpatialLike]

Get all the entities whose collision_set overlaps a circle.

Parameters:
radius: float

The radius of the circle.

point: tuple[int | float, int | float]

The center of the circle.

limit: int | None = None

A maximum amount of entities to return.

Returns:

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

get_on_point(
point: tuple[int | float, int | float],
limit: int | None = None,
) list[SpatialLike]

Get all the entities whose collision_set overlaps a point.

Parameters:
point: tuple[int | float, int | float]

The position to examine.

limit: int | None = None

A maximum amount of entities to return.

Returns:

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

remove(item: SpatialLike) None

Remove the SpatialLike instance from the SpatialHashMap.

Parameters:
item: SpatialLike

The object to remove.

validate_insert(
item: SpatialLike,
merge: bool,
) None

Issues OverlappingObjectWarnings if adding this particular item would be unplacable in the current blueprint/group configuration.