From e6f44f5be27498dea59e241eff3cfbd6bba90fff Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Sat, 2 Jan 2021 22:43:26 +0100 Subject: [PATCH] Fix lint warnings --- Sources/LibMakeColors/Model/Color+HSV.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/LibMakeColors/Model/Color+HSV.swift b/Sources/LibMakeColors/Model/Color+HSV.swift index 8b9383f..9251c03 100644 --- a/Sources/LibMakeColors/Model/Color+HSV.swift +++ b/Sources/LibMakeColors/Model/Color+HSV.swift @@ -2,26 +2,35 @@ extension Color { init(hue: Int, saturation: UInt8, value: UInt8, alpha: UInt8 = 0xFF) { let degrees = abs(hue % 360) - let s = Double(saturation) / 0xFF - let v = Double(value) / 0xFF - let C = s * v + let saturation = Double(saturation) / 0xFF + let value = Double(value) / 0xFF + + // swiftlint:disable identifier_name - Wish I knew what these actually mean. + let C = saturation * value let X = C * (1 - abs((Double(degrees) / 60).truncatingRemainder(dividingBy: 2) - 1)) - let m = v - C + let m = value - C + // swiftlint:enable identifier_name let result: (r: Double, g: Double, b: Double) switch degrees { case 0..<60: result = (C, X, 0) + case 60..<120: result = (X, C, 0) + case 120..<180: result = (0, C, X) + case 180..<240: result = (0, X, C) + case 240..<300: result = (X, 0, C) + case 300..<360: result = (C, 0, X) + default: fatalError("Degrees out of range") }