SwiftCubicSpline

CI Status Version License Platform

用法

要运行示例项目,请克隆存储库,然后首先从 Example 目录运行 pod install

要求

安装

SwiftCubicSpline 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile

pod "SwiftCubicSpline"

示例

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

作者

giordano scalzo, giordano.scalzo@gmail.com

致谢

基于 SAMCubicSplineCubicSpline

许可

SwiftCubicSpline 在 MIT 许可下可用。有关更多信息,请参见 LICENSE 文件。