Skip to content

Instantly share code, notes, and snippets.

@natmark
Created December 12, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natmark/d5a09f28b61e8f2403e7294658e45474 to your computer and use it in GitHub Desktop.
Save natmark/d5a09f28b61e8f2403e7294658e45474 to your computer and use it in GitHub Desktop.
//
// Lerp.swift
// ipad-pitagora
//
// Created by AtsuyaSato on 2017/12/12.
// Copyright © 2017年 Atsuya Sato. All rights reserved.
//
import Foundation
import UIKit
public protocol Lerpable {
func lerp(min: Self, max: Self) -> Self
}
public func lerp<T: Lerpable>(_ weighting: T, min: T, max: T) -> T {
return weighting.lerp(min: min, max: max)
}
// MARK: Lerpable implementations
extension Double: Lerpable {
/// Linear interpolation
public func lerp(min: Double, max: Double) -> Double {
return min + (self * (max - min))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment