Skip to content

Instantly share code, notes, and snippets.

@FlexMonkey
Created January 31, 2016 06:32
Show Gist options
  • Save FlexMonkey/8f3b5678bf52098f371a to your computer and use it in GitHub Desktop.
Save FlexMonkey/8f3b5678bf52098f371a to your computer and use it in GitHub Desktop.
CGFloat extension - saturate() and clamped smootherStep()
extension CGFloat
{
func saturate() -> CGFloat
{
return self < 0 ? 0 : self > 1 ? 1 : self
}
func smootherStep() -> CGFloat
{
let x = self.saturate()
return ((x) * (x) * (x) * ((x) * ((x) * 6 - 15) + 10))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment