-
-
Save natmark/d5a09f28b61e8f2403e7294658e45474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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