extension Double { func clamped(to range: ClosedRange) -> Double { return Swift.min(Swift.max(self, range.lowerBound), range.upperBound) } }