diff --git a/Sources/DynamicColor+Lab.swift b/Sources/DynamicColor+Lab.swift index 9e1b72f..1a6a2ab 100644 --- a/Sources/DynamicColor+Lab.swift +++ b/Sources/DynamicColor+Lab.swift @@ -49,12 +49,12 @@ public extension DynamicColor { let clippedB = clip(b, -128, 127) let normalized = { (c: CGFloat) -> CGFloat in - pow(c, 3) > 0.008856 ? pow(c, 3) : (c - 16 / 116) / 7.787 + pow(c, 3) > 0.008856 ? pow(c, 3) : (c - (16 / 116)) / 7.787 } let preY = (clippedL + 16) / 116 - let preX = clippedA / 500 + preY - let preZ = preY - clippedB / 200 + let preX = (clippedA / 500) + preY + let preZ = preY - (clippedB / 200) let X = 95.05 * normalized(preX) let Y = 100 * normalized(preY) @@ -75,7 +75,7 @@ public extension DynamicColor { */ final func toLabComponents() -> (L: CGFloat, a: CGFloat, b: CGFloat) { let normalized = { (c: CGFloat) -> CGFloat in - c > 0.008856 ? pow(c, 1.0 / 3) : 7.787 * c + 16.0 / 116 + c > 0.008856 ? pow(c, 1.0 / 3) : (7.787 * c) + (16.0 / 116) } let xyz = toXYZComponents() @@ -83,7 +83,7 @@ public extension DynamicColor { let normalizedY = normalized(xyz.Y / 100) let normalizedZ = normalized(xyz.Z / 108.9) - let L = roundDecimal(116 * normalizedY - 16, precision: 1000) + let L = roundDecimal((116 * normalizedY) - 16, precision: 1000) let a = roundDecimal(500 * (normalizedX - normalizedY), precision: 1000) let b = roundDecimal(200 * (normalizedY - normalizedZ), precision: 1000) diff --git a/Sources/DynamicColor+Mixing.swift b/Sources/DynamicColor+Mixing.swift index 2159871..1e32ade 100644 --- a/Sources/DynamicColor+Mixing.swift +++ b/Sources/DynamicColor+Mixing.swift @@ -86,10 +86,10 @@ public extension DynamicColor { let c1 = toLabComponents() let c2 = color.toLabComponents() - let L = c1.L + weight * (c2.L - c1.L) - let a = c1.a + weight * (c2.a - c1.a) - let b = c1.b + weight * (c2.b - c1.b) - let alpha = alphaComponent + weight * (color.alphaComponent - alphaComponent) + let L = c1.L + (weight * (c2.L - c1.L)) + let a = c1.a + (weight * (c2.a - c1.a)) + let b = c1.b + (weight * (c2.b - c1.b)) + let alpha = alphaComponent + (weight * (color.alphaComponent - alphaComponent)) return DynamicColor(L: L, a: a, b: b, alpha: alpha) } @@ -98,10 +98,10 @@ public extension DynamicColor { let c1 = toHSLComponents() let c2 = color.toHSLComponents() - let h = c1.h + weight * mixedHue(source: c1.h, target: c2.h) - let s = c1.s + weight * (c2.s - c1.s) - let l = c1.l + weight * (c2.l - c1.l) - let alpha = alphaComponent + weight * (color.alphaComponent - alphaComponent) + let h = c1.h + (weight * mixedHue(source: c1.h, target: c2.h)) + let s = c1.s + (weight * (c2.s - c1.s)) + let l = c1.l + (weight * (c2.l - c1.l)) + let alpha = alphaComponent + (weight * (color.alphaComponent - alphaComponent)) return DynamicColor(hue: h, saturation: s, lightness: l, alpha: alpha) } @@ -110,10 +110,10 @@ public extension DynamicColor { let c1 = toHSBComponents() let c2 = color.toHSBComponents() - let h = c1.h + weight * mixedHue(source: c1.h, target: c2.h) - let s = c1.s + weight * (c2.s - c1.s) - let b = c1.b + weight * (c2.b - c1.b) - let alpha = alphaComponent + weight * (color.alphaComponent - alphaComponent) + let h = c1.h + (weight * mixedHue(source: c1.h, target: c2.h)) + let s = c1.s + (weight * (c2.s - c1.s)) + let b = c1.b + (weight * (c2.b - c1.b)) + let alpha = alphaComponent + (weight * (color.alphaComponent - alphaComponent)) return DynamicColor(hue: h, saturation: s, brightness: b, alpha: alpha) } @@ -122,10 +122,10 @@ public extension DynamicColor { let c1 = toRGBAComponents() let c2 = color.toRGBAComponents() - let red = c1.r + weight * (c2.r - c1.r) - let green = c1.g + weight * (c2.g - c1.g) - let blue = c1.b + weight * (c2.b - c1.b) - let alpha = alphaComponent + weight * (color.alphaComponent - alphaComponent) + let red = c1.r + (weight * (c2.r - c1.r)) + let green = c1.g + (weight * (c2.g - c1.g)) + let blue = c1.b + (weight * (c2.b - c1.b)) + let alpha = alphaComponent + (weight * (color.alphaComponent - alphaComponent)) return DynamicColor(red: red, green: green, blue: blue, alpha: alpha) } diff --git a/Sources/DynamicColor+XYZ.swift b/Sources/DynamicColor+XYZ.swift index cd48667..57bfee8 100644 --- a/Sources/DynamicColor+XYZ.swift +++ b/Sources/DynamicColor+XYZ.swift @@ -54,9 +54,9 @@ public extension DynamicColor { return abs(roundDecimal(rgb, precision: 1000)) } - let red = toRGB(clippedX * 3.2406 + clippedY * -1.5372 + clippedZ * -0.4986) - let green = toRGB(clippedX * -0.9689 + clippedY * 1.8758 + clippedZ * 0.0415) - let blue = toRGB(clippedX * 0.0557 + clippedY * -0.2040 + clippedZ * 1.0570) + let red = toRGB((clippedX * 3.2406) + (clippedY * -1.5372) + (clippedZ * -0.4986)) + let green = toRGB((clippedX * -0.9689) + (clippedY * 1.8758) + (clippedZ * 0.0415)) + let blue = toRGB((clippedX * 0.0557) + (clippedY * -0.2040) + (clippedZ * 1.0570)) self.init(red: red, green: green, blue: blue, alpha: alpha) } @@ -80,9 +80,9 @@ public extension DynamicColor { let green = toSRGB(rgba.g) let blue = toSRGB(rgba.b) - let X = roundDecimal((red * 0.4124 + green * 0.3576 + blue * 0.1805) * 100, precision: 1000) - let Y = roundDecimal((red * 0.2126 + green * 0.7152 + blue * 0.0722) * 100, precision: 1000) - let Z = roundDecimal((red * 0.0193 + green * 0.1192 + blue * 0.9505) * 100, precision: 1000) + let X = roundDecimal(((red * 0.4124) + (green * 0.3576) + (blue * 0.1805)) * 100, precision: 1000) + let Y = roundDecimal(((red * 0.2126) + (green * 0.7152) + (blue * 0.0722)) * 100, precision: 1000) + let Z = roundDecimal(((red * 0.0193) + (green * 0.1192) + (blue * 0.9505)) * 100, precision: 1000) return (X: X, Y: Y, Z: Z) } diff --git a/Sources/HSL.swift b/Sources/HSL.swift index 0a9aebb..b138c08 100644 --- a/Sources/HSL.swift +++ b/Sources/HSL.swift @@ -84,13 +84,13 @@ internal struct HSL { } if rgba.r == maximum { - h = (rgba.g - rgba.b) / delta + (rgba.g < rgba.b ? 6 : 0) + h = ((rgba.g - rgba.b) / delta) + (rgba.g < rgba.b ? 6 : 0) } else if rgba.g == maximum { - h = (rgba.b - rgba.r) / delta + 2 + h = ((rgba.b - rgba.r) / delta) + 2 } else if rgba.b == maximum { - h = (rgba.r - rgba.g) / delta + 4 + h = ((rgba.r - rgba.g) / delta) + 4 } } @@ -109,9 +109,9 @@ internal struct HSL { let m2 = l <= 0.5 ? l * (s + 1) : (l + s) - (l * s) let m1 = (l * 2) - m2 - let r = hueToRGB(m1: m1, m2: m2, h: h + 1 / 3) + let r = hueToRGB(m1: m1, m2: m2, h: h + (1 / 3)) let g = hueToRGB(m1: m1, m2: m2, h: h) - let b = hueToRGB(m1: m1, m2: m2, h: h - 1 / 3) + let b = hueToRGB(m1: m1, m2: m2, h: h - (1 / 3)) return DynamicColor(red: r, green: g, blue: b, alpha: CGFloat(a)) } @@ -121,13 +121,13 @@ internal struct HSL { let hue = moda(h, m: 1) if hue * 6 < 1 { - return m1 + (m2 - m1) * hue * 6 + return m1 + ((m2 - m1) * hue * 6) } else if hue * 2 < 1 { return CGFloat(m2) } else if hue * 3 < 1.9999 { - return m1 + (m2 - m1) * (2 / 3 - hue) * 6 + return m1 + ((m2 - m1) * (2 / 3 - hue) * 6) } return CGFloat(m1) @@ -142,7 +142,7 @@ internal struct HSL { - returns: A HSL color with the hue changed. */ func adjustedHue(amount: CGFloat) -> HSL { - return HSL(hue: h * 360 + amount, saturation: s, lightness: l, alpha: a) + return HSL(hue: (h * 360) + amount, saturation: s, lightness: l, alpha: a) } /**