What is @types/rbush?
@types/rbush provides TypeScript type definitions for the rbush library, which is a high-performance JavaScript library for spatial indexing of 2D geometries. It allows for efficient querying and manipulation of spatial data structures such as points, rectangles, and polygons.
What are @types/rbush's main functionalities?
Inserting Items
This feature allows you to insert items into the spatial index. The items are typically bounding boxes defined by their minimum and maximum X and Y coordinates.
const RBush = require('rbush');
const tree = new RBush();
tree.insert({ minX: 20, minY: 40, maxX: 30, maxY: 50 });
Bulk Insertion
This feature allows for bulk insertion of multiple items into the spatial index, which is more efficient than inserting items one by one.
const items = [
{ minX: 20, minY: 40, maxX: 30, maxY: 50 },
{ minX: 10, minY: 20, maxX: 15, maxY: 25 }
];
tree.load(items);
Searching
This feature allows you to search for items within a given bounding box. The search returns all items that intersect with the specified bounding box.
const searchResult = tree.search({ minX: 15, minY: 25, maxX: 35, maxY: 45 });
Removing Items
This feature allows you to remove items from the spatial index. The item to be removed must match exactly with an item in the index.
tree.remove({ minX: 20, minY: 40, maxX: 30, maxY: 50 });
Bounding Box Calculation
This feature allows you to calculate the bounding box of an item. This is useful for custom data structures where you need to define how to extract the bounding box.
const bbox = tree.toBBox({ minX: 20, minY: 40, maxX: 30, maxY: 50 });
Other packages similar to @types/rbush
geokdbush
geokdbush is a library for fast geospatial indexing and querying of points using a K-D tree. It is optimized for geographic coordinates and provides efficient nearest neighbor searches. Compared to rbush, geokdbush is more specialized for point data and geographic coordinates.
flatbush
flatbush is a fast static spatial index for 2D points and rectangles. It is designed for use cases where the index is built once and queried many times. flatbush is more memory-efficient and faster for read-only use cases compared to rbush, which supports dynamic updates.
rtree
rtree is a library for creating and querying R-trees, which are a type of spatial index. It supports dynamic insertion and deletion of items. Compared to rbush, rtree provides similar functionality but may have different performance characteristics depending on the specific use case.