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

插件详情v1.2.0

dart_earcut

基于 https://github.com/mapbox/earcut 的高性能三角剖分算法

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
114万
喜欢数
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.

所属分类

源码仓库

使用此插件的项目