SwiftCubicSpline 2.0.0

SwiftCubicSpline 2.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2020年3月
SPM支持 SPM

Giordano Scalzo 维护。



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, [email protected]

致谢

基于 SAMCubicSplineCubicSpline

许可证

SwiftCubicSpline 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。