Swiftpack.co - gscalzo/SwiftCubicSpline as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by gscalzo.
gscalzo/SwiftCubicSpline 2.0.0
Swift implementation of cubic spline interpolation (https://en.wikipedia.org/wiki/Spline_interpolation)
⭐️ 26
🕓 4 years ago
.package(url: "https://github.com/gscalzo/SwiftCubicSpline.git", from: "2.0.0")

SwiftCubicSpline

CI Status Version License Platform

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

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

pod "SwiftCubicSpline"

Example

let spline = CubicSpline(points: [
    Point(x: 0.0, y: 0.5),
    Point(x: 0.1, y: 0.5),
    Point(x: 0.2, y: 0.7),
    Point(x: 0.4, y: 0.3),
    Point(x: 0.6, y: 0.6),
    Point(x: 0.8, y: 0.4),
    Point(x: 0.9, y: 0.5),
    Point(x: 1.0, y: 0.5)
    ])

let graphSize = self.bounds.size
for y in 0 ..< Int(graphSize.height) {
    let y = Double(y)
    let x = spline[x: y/Double(graphSize.height)] * Double(graphSize.width)

    if y == 0 {
        context.move(to: CGPoint(x: x, y: y))
    } else {
        context.addLine(to: CGPoint(x: x, y: y))
    }
}
context.strokePath()

screenshot

Author

giordano scalzo, [email protected]

Credits

Based on SAMCubicSpline and CubicSpline

License

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

GitHub

link
Stars: 26
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics