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

套件詳情v0.0.4

sweepline_intersections

一個小型且快速的模組,使用掃描線演算法來偵測多邊形和/或折線之間的相交。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
16.2萬
喜歡數
7
Pub 分數
150

安裝套件

flutter pub add sweepline_intersections

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個輕量級且高效率的 Dart 套件,使用掃描線演算法來有效偵測多邊形與折線之間的交點。專為二維空間中的幾何運算設計,提供快速的交點偵測,非常適合需要即時或批次處理複雜形狀的應用程式。此套件具備平台無關性,支援所有主要的 Flutter 平台。它在準確性與速度方面經過優化,適用於地理資訊系統、電腦輔助設計以及視覺化工具。

適用情境

  • 即時多邊形碰撞檢測
  • GIS空間分析
  • CAD圖紙驗證
  • 互動式地圖功能
  • 用於渲染的幾何預處理
  • 遊戲中的碰撞檢測

主要特色

  • 高速交點檢測
  • 掃描線演算法實作
  • 支援多邊形與折線
  • 跨平台相容性
  • 最小記憶體佔用
  • 精確的幾何結果

適合對象

  • 開發互動地圖的開發者
  • 需要幾何形狀分析的應用程式
  • 用於CAD或設計軟件的工具
  • 具有複雜碰撞系統的遊戲
  • 性能關鍵的幾何操作

使用建議

  • 最適合二維幾何
  • 需要正確閉合的多邊形才能獲得準確結果
  • 未針對無批次處理的極大資料集進行優化
  • 僅限線段與多邊形相交

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Ported from: rowanwins/sweepline-intersections

sweepline-intersections

A small and fast module using a sweepline algorithm to detect intersections between polygons and/or polylines.

Documentation

Install
dart pub add sweepline_intersections
Basic Use

Valid inputs: Geojson Feature or Geometry including Polygon, LineString, MultiPolygon, MultiLineString, as well as FeatureCollection.

Returns a List of intersection Points eg, [Point(coordinates:Position(lng:x1, lat:y1)), Point(coordinates:Position(lng:x2, lat:y2)]

    var box = Feature(geometry: Polygon(coordinates: [[Position.of([0, 0]), Position.of([1, 0]), Position.of([1, 1]), Position.of([0, 1]), Position.of([0, 0])]]));
    var intersections = sweeplineIntersections(box);
    // returns a List of self-intersection Points

Also accepts an optional boolean argument second which when set to true means the module won't detect self-intersections and will only report intersections between different features. This defaults to false. eg

    var intersectionsBetweenFeature = sweeplineIntersections(featureCollection, true);
    // returns a List of intersection Points between Features
Complex Use

This library also provide a class-based approach which is helpful if you want to check multiple geometries against a single geometry. This allows you to save the state of the initial event queue with the primary geometry.

    import 'package:sweepline_intersections/sweepline_intersections.dart';
    main(){
    // create the base instance
    var sl = SweeplineIntersections();
    sl.addData(aGeom);
    // clone the event queue in the original state so you can reuse it
    var origQueue = sl.cloneEventQueue();
    List<Position> positions = [
    Position.of([21.93869948387146, 49.99897434944081]),
    Position.of([21.93869948387100, 49.99897434944032]),
    ];
    var f = FeatureCollection(
    features: [
      Feature(
        geometry: LineString(coordinates: positions),
      ),
    ],
    );    // now you can iterate through some other set of features saving
    // the overhead of having to populate the complete queue multiple times
    for (var feature in f.features) {
    // add another feature to test against your original data
    sl.addData(feature, alternateEventQueue: origQueue);
    // check if those two features intersect
    // add an optional boolean argument to ignore self-intersections
    }
    var intersectionPoints = sl.getIntersections(true);
    }
API

SweeplineIntersectionsClass() - creates a new instance

.addData(geojson, existingQueue) - adds geojson to the event queue. The second argument for an existingQueue is optional, and takes a queue generated from .cloneEventQueue()

.cloneEventQueue() - clones the state of the existing event queue that's been populated with geojson. Returns a queue that you can pass to the addData method

.getIntersections(ignoreSelfIntersections) - Checks for segment intersections. Accepts an optional boolean argument to ignore self intersections are only report intersections between features.

Contributing

Algorithm notes

The basic concept of this algorithm is based on a sweepline. Where this algorithm differs from the bentley-ottmann algorithm is that there is no use of a tree data structure to store the segments. The reason for the modification is because if you are dealing with polygons or polylines (rather than a random group of line segments) there is a reasonable assumption that there are going to be very few segments that lie on the same x plane.

Removing the tree structure greatly simplifies the code. The tree structure is replaced with a priority queue of segments which is sorted by the x vertex of the right endpoint of the segments. A priority queue is already used to sort the vertices which means only 1 data structure is required.

Algorithm Steps
  • Vertices are entered into a priority queue sorted from left to right
  • An empty priority queue is created to store segments encountered
  • An item is removed from the priority queue
    • If the vertex is the left endpoint of a segment, we test it against every other segment in the segment queue for intersections with any intersection recorded. We then add the vertex (and it's associated right endpoint) to the segment queue.
    • When we encounter a right endpoint we remove the first item from the segment queue.

Each pair of segments are only tested once. And only segments that overlap on the x plane are tested against each other.

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案