Skip to content

A Swift Library that builds concave hull by set of points

License

Notifications You must be signed in to change notification settings

Syncheo/ConcaveHull

Repository files navigation

ConcaveHull - A Swift Library that builds concave hull by set of points

CI Status Version License Platform

Usage

let points = [[162, 332], [182, 299], [141, 292], [158, 264], ... ];
let h = Hull(concavity: 50)
let hull = h.hull(points, nil)

Params

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 default 20;
  • 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

Determining an appropriate concavity parameter value

Concavity determines the hull's maximum edge length.

  • Calculate the diameter of your dataset.
  • Start experimenting with: concavity = diameter / 5.

How it works

This step by step guide was taken as the original code from https://github.com/AndriiHeonia/hull Let's see step by step what happens when you call hull() function:

  1. Hull.js takes your source points of the shape:
  2. Builds convex hull:
  3. After that, the edges flex inward (according to the `concavity` param). For example:
    `concavity = 80`
    `concavity = 40`
    `concavity = 20`
## Installation

ConcaveHull is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "ConcaveHull"

About

A Swift Library that builds concave hull by set of points

Resources

License

Stars

Watchers

Forks

Packages

No packages published