public extension Double {
    static func clamp(_ x: Self, lowerBound minValue: Self, upperBound maxValue: Self) -> Self {
        max(minValue, min(x, maxValue))
    }

    func clamped(lowerBound: Self, upperBound: Self) -> Self {
        Self.clamp(self, lowerBound: lowerBound, upperBound: upperBound)
    }
}
