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

套件詳情v1.2.0

dart_earcut

基於 https://github.com/mapbox/earcut 的高效能三角剖分演算法

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
109萬
喜歡數
10
Pub 分數
150

安裝套件

flutter pub add dart_earcut

套件介紹

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

dart_earcut 是一個高效率的 Dart 三角剖分函式庫,實作了 Mapbox 最初開發的 Earcut 算法。它能有效將多邊形形狀轉換為三角形,非常適合用於 2D 圖形與視覺化應用中複雜幾何圖形的呈現。此套件支援 Android、iOS、Web、macOS、Windows 與 Linux 多個平台,確保跨平台的一致性。設計上著重於速度與準確性,可處理帶有洞的簡單與複雜多邊形,為計算幾何任務提供可靠結果。

適用情境

  • 2D 遊戲開發
  • 基於Web的地圖渲染
  • 向量圖形處理
  • 互動式資料視覺化
  • UI 元件的網格產生

主要特色

  • 快速三角剖分效能
  • 支援帶洞的多邊形
  • 跨平台相容性
  • 多邊形輸入的簡單 API
  • 複雜形狀的精確結果

適合對象

  • 圖形開發人員
  • GIS應用創建者
  • UI/UX 設計師使用自定義形狀
  • 遊戲引擎整合商
  • 數據可視化工程師

使用建議

  • 需要有效的多邊形輸入(非相交邊)
  • 未針對即時動態更新進行優化
  • 限制為2D三角剖分
  • 不直接處理自相交多邊形
  • 可能需要對不規則輸入進行預處理

原始 README

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

dart_earcut

Ear-clipping (earcutting) triangulation algorithm, ported (with minor API differences) from earcut4j/earcut4j and mapbox/earcut. Also includes the fix from mapbox/earcut#91.

Usage

  • 2D (x/y) coordinates, without holes

    • triangulateRaw: expects points in the format [x0, y0, x1, y1, x2, y2, ...]
    • triangulateFromPoints: expects 'dart:math's Point objects
    final triangles = Earcut.triangulateRaw([10,0, 0,50, 60,60, 70,10]);
    final triangles = Earcut.triangulateFromPoints([Point(10, 0), Point(0,50), Point(60,60), Point(70,10)]);
    // Both return [1,0,3, 3,2,1]
    
  • Holes
    A list of hole indicies, if any. For example, [5, 8] for a 12-vertice input would mean one hole with vertices 5-7 and another with 8-11. If you pass a single vertice as a hole, Earcut treats it as a Steiner point.

    final List<int> triangles = Earcut.triangulateRaw([0, 0, 100, 0, 100, 100, 0, 100, 20, 20, 80, 20, 80, 80, 20, 80], holeIndices: [4]);
    // Returns [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2]
    
    • triangulateFromPointsAndHolePoints performs the logic to generate holeIndices when the outline of a polygon and the outline of its holes are available as points seperately.
  • More dimensions
    Expected to be in the format [x0, y0, z0, x1, y1, z1, x2, y2, z2, ...]

    final List<int> triangles = Earcut.triangulateRaw([10, 0, 1, 0, 50, 2, 60, 60, 3, 70, 10, 4], dimensions: 3);
    // Returns [1,0,3, 3,2,1]
    

The Algorithm

The library implements a modified ear slicing algorithm, optimized by z-order curve hashing and extended to handle holes, twisted polygons, degeneracies and self-intersections in a way that doesn't guarantee correctness of triangulation, but attempts to always produce acceptable results for practical data.

It's based on ideas from FIST: Fast Industrial-Strength Triangulation of Polygons by Martin Held andTriangulation by Ear Clipping by David Eberly.

所屬分類

原始碼儲存庫

使用此套件的專案