js-quadtree is a JavaScript library providing a robust and configurable quadtree implementation, suitable for both Node.js environments and direct browser usage. Currently at stable version 3.3.6, the library appears to follow an infrequent release cadence, with recent updates primarily consisting of minor version bumps without significant feature changes or breaking modifications. Its key differentiators include the ability to specify maximum capacity per node, automatic removal of empty sub-nodes, configurable maximum depth to prevent excessive subdivision, and a customizable point equality comparison function crucial for accurate removal operations when dealing with custom data. It supports inserting plain objects with `x` and `y` properties in addition to its own `Point` objects, which can hold arbitrary custom data, making it flexible for various spatial indexing needs.
npm install js-quadtreeVerified import paths — ran on the pinned version, not inferred.
Demonstrates quadtree creation, configuration, insertion of various point types (including custom data and plain objects), querying with a circular region, and point removal, showcasing common API interactions.
Always prefix class constructors with `QT.` (e.g., `new QT.QuadTree()`, `new QT.Point()`) when using the CDN build in a browser environment.
Pass a `config` object to the `QuadTree` constructor with a custom `arePointsEqual` property that implements your desired comparison logic (e.g., `(p1, p2) => p1.x === p2.x && p1.y === p2.y && p1.data.id === p2.data.id`).
Tune `capacity` and `maximumDepth` parameters based on your specific application's data distribution and performance requirements. For static or mostly additive data sets, consider disabling `removeEmptyNodes` if the overhead is noticeable. Profile your application to find optimal values.
In browser CDN usage, access classes via the global `QT` object: `new QT.QuadTree(...)`, `new QT.Box(...)`, etc. Ensure proper ESM/CJS imports in Node.js: `import { QuadTree } from 'js-quadtree';` or `const { QuadTree } = require('js-quadtree');`.Ensure all objects inserted into or removed from the quadtree conform to the expected interface by having both `x` and `y` numeric properties, either as `Point` instances or custom objects.
Verify that the `Point` object passed to `remove()` is identical to one previously inserted. If using custom data, implement a custom `arePointsEqual` function in the `QuadTree` configuration that accurately compares unique identifiers or relevant properties within your `data` objects.
No dependency data recorded yet.