HashGrid

class HashGrid(val radius: Double)(source)

Represents a 2D spatial hash grid used for efficiently managing and querying points in a sparse space.

Constructors

Link copied to clipboard
constructor(radius: Double)

Properties

Link copied to clipboard

Represents the size of a single cell in the hash grid.

Link copied to clipboard

The maximum distance between points for them to be considered neighbors.

Link copied to clipboard
var size: Int

Represents the total number of elements (points or data) that are currently stored in the grid.

Functions

Link copied to clipboard
fun cell(query: Vector2): Cell?

Retrieves the cell corresponding to the given query point in the grid. The method calculates the grid coordinates for the query point and returns the cell found at those coordinates, if it exists.

Link copied to clipboard

Returns a sequence of all cells stored in the grid. Iterates through the values in the internal cells map and yields each cell.

Link copied to clipboard
fun insert(point: Vector2, owner: Any? = null)

Inserts a point into the grid, associating it with an owner if provided. The method calculates the grid cell corresponding to the provided point and inserts the point into that cell. If the cell does not exist, it is created.

Link copied to clipboard
fun isFree(query: Vector2, ignoreOwners: Set<Any> = emptySet()): Boolean

Checks if a specific query point in 2D space is free from any nearby points or owners, according to the internal grid structure and other constraints.

Link copied to clipboard
fun points(): Sequence<Pair<Vector2, Any?>>

Generates a sequence of all points stored within the grid.

Link copied to clipboard
fun random(random: Random = Random.Default): Vector2

Selects a random point from the grid using the provided random number generator.