spatial_data_structure

class SpatialDataStructure

An abstract class used to implement some kind of spatial querying accelleration, such as a spatial hash-map or quadtree.

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

Add a SpatialLike instance to the SpatialHashMap.

Param:

The object to add.

abstract clear() None

Deletes all entries in the structure.

abstract 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.

abstract get_in_area(area: AABB, limit: int = 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.

abstract get_in_radius(radius: float, point: Sequence[float], limit: int = 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.

abstract get_on_point(point: 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.

abstract recursive_add(item: SpatialLike, merge: bool = False) 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).

abstract recursive_remove(item: SpatialLike) None

Inverse of recursive_add().

Parameters:

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

abstract remove(item: SpatialLike) None

Remove the SpatialLike instance from the SpatialHashMap.

Parameters:

item – The object to remove.