@@ -6,12 +6,24 @@ public enum SmoothGradientInterpolation {
6
6
}
7
7
8
8
/// Define the number of intermediate colors to generate.
9
- public enum SmoothGradientPrecision : Int {
10
- case low = 1
11
- case lowMedium = 3
12
- case medium = 5
13
- case mediumHigh = 7
14
- case high = 9
9
+ public enum SmoothGradientPrecision {
10
+ case low
11
+ case lowMedium
12
+ case medium
13
+ case mediumHigh
14
+ case high
15
+ case custom( Int )
16
+
17
+ func precisionToCount( ) -> Int {
18
+ switch self {
19
+ case . low: return 1
20
+ case . lowMedium: return 3
21
+ case . medium: return 5
22
+ case . mediumHigh: return 7
23
+ case . high: return 9
24
+ case . custom( let value) : return value
25
+ }
26
+ }
15
27
}
16
28
17
29
protocol RGBColorConvertible {
@@ -35,7 +47,7 @@ public struct SmoothGradientGenerator {
35
47
interpolation: SmoothGradientInterpolation = . hcl,
36
48
precision: SmoothGradientPrecision = . medium
37
49
) -> [ RGBColor ] {
38
- let count = precision. rawValue
50
+ let count = precision. precisionToCount ( )
39
51
return interpolate ( from: from, to: to, count: count, interpolation: interpolation)
40
52
}
41
53
@@ -68,7 +80,7 @@ public struct SmoothGradientGenerator {
68
80
) -> [ LCHColor ] {
69
81
switch interpolation {
70
82
case . hcl:
71
- let count = precision. rawValue
83
+ let count = precision. precisionToCount ( )
72
84
return interpolate ( from: from, to: to, count: count)
73
85
default :
74
86
return generateAsRGBColor (
@@ -93,7 +105,7 @@ public struct SmoothGradientGenerator {
93
105
) -> [ HSLColor ] {
94
106
switch interpolation {
95
107
case . hsl:
96
- let count = precision. rawValue
108
+ let count = precision. precisionToCount ( )
97
109
return interpolate ( from: from, to: to, count: count)
98
110
default :
99
111
return generateAsRGBColor (
@@ -118,7 +130,7 @@ public struct SmoothGradientGenerator {
118
130
) -> [ HSBColor ] {
119
131
switch interpolation {
120
132
case . hsb:
121
- let count = precision. rawValue
133
+ let count = precision. precisionToCount ( )
122
134
return interpolate ( from: from, to: to, count: count)
123
135
default :
124
136
return generateAsRGBColor (
0 commit comments