搜索插件、代码仓与 APP 分类

插件详情v1.1.1

rbush

RBush — 一种高性能的基于 R 树的二维空间索引,用于点和矩形。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
18.5万
喜欢数
11
Pub 分数
140

安装插件

flutter pub add rbush

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

RBush 是一个高性能的基于 R 树的空间索引,专为高效处理点和矩形的 2D 几何操作而设计。它支持快速范围查询、最近邻搜索以及碰撞检测,适用于涉及空间数据的应用程序。该包专为 Dart 开发,可无缝集成到所有主要平台的 Flutter 项目中。该软件包非常适合游戏、地图系统以及任何需要快速空间查找的应用。其实现经过优化,具有出色的运行速度和内存效率,适用于实时或大规模的空间处理。

适合场景

  • 地理空间数据索引
  • 游戏对象碰撞检测
  • 基于地图的应用程序
  • 实时邻近查询
  • 空间搜索优化

主要特点

  • 高性能 R 树索引
  • 支持点和矩形
  • 针对2D空间查询进行了优化
  • 跨平台兼容性
  • 低内存开销

适合对象

  • 开发交互式地图的开发者
  • 需要空间碰撞检测的游戏开发者
  • 频繁空间查询的应用程序
  • 性能关键的地理空间工具
  • 需要快速2D几何运算的Flutter应用

使用建议

  • 仅适用于2D数据
  • 对于频繁插入/删除的动态数据集来说并不理想
  • 需要仔细处理坐标系
  • 仅限点和矩形几何形状
  • 不支持复杂形状或多边形的内置支持

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

RBush

RBush is a high-performance Dart library for 2D spatial indexing of points and rectangles. It's based on an optimized R-tree data structure with bulk insertion support.

Spatial index is a special data structure for points and rectangles that allows you to perform queries like "all items within this bounding box" very efficiently (e.g. hundreds of times faster than looping over all items). It's most commonly used in maps and data visualizations.

Usage

// Create a tree with up to 16 elements in a leaf.
final tree = RBush(16);

// Bulk load elements (empty in this case, so here it's a no-op).
tree.load(<RBushElement>[]);

// Insert a single element.
tree.insert(RBushElement(
  minX: 10, minY: 10,
  maxX: 20, maxY: 30,
  data: 'sample data'
));

// Find the element we've inserted.
final List<RBushElement> found = tree.search(
    RBushBox(minX: 5, minY: 5, maxX: 25, maxY: 25));

// Remove all elements from the tree.
tree.clear();

An optional argument to RBush defines the maximum number of entries in a tree node. 9 (used by default) is a reasonable choice for most applications. Higher value means faster insertion and slower search, and vice versa.

To store items of a different type, extend from (or instantiate) RBushBase<T>. For example:

class MyItem {
  final String id;
  final LatLng location;
  
  const MyItem(this.id, this.location);
}

final tree = RBushBase<MyItem>(
  maxEntries: 4,
  toBBox: (item) => RBushBox(
    minX: item.location.longitude,
    maxX: item.location.longitude,
    minY: item.location.latitude,
    maxY: item.location.latitude,
  ),
  getMinX: (item) => item.location.longitude,
  getMinY: (item) => item.location.latitude,
);
K Nearest Neighbours

The RBushBase class also includes a knn() method for the nearest neighbours search. This is especially useful when using the r-tree to store point features, like in the example above.

Note that for larger geographical areas the distance would be wrong, since the class uses pythagorean distances (dx² + dy²), not Haversine or great circle.

Tiny Queue and Quick Select

This package also includes ported fast versions of a priority queue and a selection algorithm. These are used internally by the r-tree, but might be useful for you as well.

Upstream

This library is a straight-up port of several JavaScript libraries written by Vladimir Agafonkin:

All of these are published under MIT or ISC licenses.

所属分类

源码仓库

使用此插件的项目