kdtreepoint3d Reference
Module defined in `lua/common/kdtreepoint3d.lua`. K-d tree implementation for 3D points with range queries AND nearest-neighbor (closest point) queries.
Module defined in lua/common/kdtreepoint3d.lua. K-d tree implementation for 3D points with range queries AND nearest-neighbor (closest point) queries.
Exports
Functions
kdtreepoint3d.new(itemCount)
Creates a new empty 3D point k-d tree.
- Parameters:
itemCount- number|nil - Expected item count for pre-allocation
- Returns: kdTree - Tree object
Instance Methods
tree:preLoad(id, x, y, z)
Adds a point to the pre-load buffer.
- Parameters:
id- any - Item identifierx, y, z- number - Point coordinates
tree:build()
Constructs the k-d tree from pre-loaded points.
tree:query(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)
Range query - returns iterator over all points within the query box. Safe for nested queries.
- Returns: function, table - Iterator yielding item IDs
tree:queryNotNested(query_xmin, query_ymin, query_zmin, query_xmax, query_ymax, query_zmax)
Faster range query reusing internal state; not safe for nesting.
- Returns: function, table - Iterator
tree:findNearest(x, y, z)
Finds the closest point to the query position.
- Parameters:
x, y, z- number - Query point coordinates
- Returns: any, number - ID of nearest item and Euclidean distance to it
tree:export() / tree:import(kdTreeData)
Serialization/deserialization.
tree:analytics()
Prints tree statistics.
Internal Notes
- Items stored as flat array: 4 values per item (x, y, z, id)
findNearestuses branch-and-bound with the median point as initial best-distance estimate- Same LEF Select and flat-array structure as the box variants
- Nearest-neighbor search prunes branches when the squared distance to the split plane exceeds best distance
Additional Exports
| Key | Signature | Description |
|---|---|---|
M.new | (itemCount) | (No description available) |
kdtreebox3d Reference
Module defined in `lua/common/kdtreebox3d.lua`. K-d tree implementation for 3D axis-aligned bounding boxes (6 dimensions: xmin, ymin, zmin, xmax, ymax, zmax). Efficient spatial range queries for 3D bo
lpack Reference
Module defined in `lua/common/lpack.lua`. Fast Lua de/serializer supporting three formats: packed text, binary (using `string.buffer`), and Lua source. Handles tables, numbers, strings, booleans, vec3