A typed, spatial partitioning grid for fast proximity queries, where entities are stored in a uniform grid, allowing lookups of nearby objects without querying the entitre dataset.
const grids = require(THIS_MODULE)
const grid = gridModule.newGrid(1900)
const entityId = grids.spawn(grid, part, Vector3)
grids.updatePosition(grid, entityId, Vector3)
grids.remove(grid, entityId or part)
const parts = grids.query(grid, Vector3, radius?)
const entityIds = grids.queryAllInRadius(grid, Vector3, radius)
const x, z = grids.getCellCoords(grid, position)
const x, z = grids.getCellKey(grid, id or position)
grids.empty(grid)
grids.destroy(grid) This module contains heavy AI generated material from ChatGPT 5.3 or lower (free plan). It was a bit frustrating since ChatGPT would remove some of the public functions and change local to const since it believed that it doesn't exist in Luau, while it most certainly did in later releases.
Additionally, it mixed up Luau with vanilla Lua versions past 5.1, claiming that ~ is a pure operator in Luau while it is not in the time of writing.
This module was a bit of an experiment, as I challenged ChatGPT to replace this particular function:
const function _getNearbySources(signPos: Vector3, sources: types.SourceList, maxDistance: number): { types.LightSource }
const nearby: { types.LightSource } = {}
for _, source in sources do
if source.isActive() then
const dist = (source.getPosition() - signPos).Magnitude
if dist <= maxDistance then
nearby[#nearby + 1] = source
end
end
end
return nearby
endThis work is openly licensed under the BSD-2-Clause-Patent OR the Apache License 2.0. You may choose either license at your discretion.