ConcaveHull - 一个通过点集构建凹多边形边界的 Swift 库
用法
let points = [[162, 332], [182, 299], [141, 292], [158, 264], ... ];
let h = Hull(concavity: 50)
let hull = h.hull(points, nil)
参数
public func hull(_ pointSet: [Any], _ concavity: Double?, _ format: [String]?) -> [Any] {
- 1st param - array of coordinates in format:
[Any]
,[Any]
can be [[Int]], [[Double]], [[String: Int]], [[String: Double]]; - 2nd param - concavity.
1
- thin shape.Infinity
- convex hull. By default20
; - 3rd param - the format of the array of coordinates For example:
["lng", "lat"]
if you have["lng": x, "lat": y]
points. If your are using [[Int]] or [[Double]], the value can be nil
工作原理
这个逐步指南基于GitHub 上的原始代码https://github.com/AndriiHeonia/hull。让我们一步一步看看调用 hull()
函数时会发生什么。
-
Hull.js 可以接收你的形状的源点
-
构建凸包
-
之后,边框会向内弯曲(根据`concavity`参数)。例如
ConcaveHull 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "ConcaveHull"