A simple API to get the length of a CGPath, UIBezierPath or NSBezierPath, written in Swift.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
BezierPathLength macOS
BezierPathLength tvOS Make headers empty Sep 3, 2017
BezierPathLength watchOS Make headers empty Sep 3, 2017
BezierPathLength.xcodeproj
BezierPathLength.xcworkspace
BezierPathLengthTests Swiftlint autocorrect Feb 26, 2017
Example Update to Swift 4 and Xcode 9.0 Sep 13, 2017
Source
calculations-resources Added overview to calculations.md Nov 20, 2016
.codeclimate.yml Added Code Climate config Nov 24, 2016
.editorconfig
.gitattributes
.gitignore
.swift-version Update .swift-version Sep 19, 2017
.travis.yml
BezierPathLength.podspec
LICENSE
README.md Update README Jan 26, 2018
calculations.md
codecov.yml

README.md

[UI/NS]BezierPath + Length

Build Status codecov Code Climate Swift PodVersion platform Twitter Donate

This project provides a simple API to get the length of either a UIBezierPath or NSBezierPath. Example:

let rect = CGRect(origin: .zero, size: CGSize(width: 100, height: 300))
let path = UIBezierPath(ovalIn: rect)

// Length in pt.
let length = path.length

There's also an API for getting a point on a path at a certain percentage, example:

// CGPoint at 50% of path
let point = path.point(at: 0.5)

Requirements

  • iOS 8.0+ / macOS 10.9+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 9.0+

Installation

CocoaPods

To install, add the following line to your Podfile:

pod 'BezierPathLength', '~> 1.0.0'

How does it work?

The actual calculations are implemented on a CGPath extension, but a [UI/NS]BezierPath extension is available for convenience.

Any CGPath can be split into subpaths. Of which there are three types:

  • Linear
  • Quadratic curve
  • Cubic curve

See calculations.md for a detailed mathematical explanation of how the length of these three can be calculated.

License

This project is available under the MIT license. See the LICENSE file for more info.