搜尋套件、儲存庫與 APP 分類

套件詳情v1.1.1

rbush

RBush — 一種高效率的基於 R 樹的 2D 空間索引,適用於點和矩形。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
17.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.

所屬分類

原始碼儲存庫

使用此套件的專案