v4.0 — Serializable KDBush
Reimplements KDBush to store the whole index along with its properties in a single array buffer for easy transfer and serialization. Closes #31. Closes #25. Closes #23. cc @hydrosquall
Breaks the API to support this in the same way as Flatbush:
// old API
const index = new KDBush(points, p => p.x, p => p.y, 64, Uint32Array);
// new API
const index = new KDBush(points.length, 64, Uint32Array);
for (const {x, y} of points) index.add(x, y);
index.finish();
The new API is more verbose, but it allows creating an index without requiring to store coordinates in some intermediate point array, allowing more efficient memory use.
To do:
- [x] New format and API
- [x] Deserialization
- [x] Cover new API with tests
- [ ] Update readme
Great to see this, thanks @mourner !
Hello!
Is this new API avaible?
I am trying to build a static KDTree that I can save as a JSON. The static KDTree will then be loaded as a JSON into my site as a reference for indexing for user-defined points. This is possible? I am able to make the JSON but once I load it in I lose the .range extension. Any suggestion would be greatly appreciated :)
Cheers, Chris