Skip to content

Commit 7f14258

Browse files
authored
Merge pull request #3 from BeehiveInnovations/main
dynamic library support + custom precision
2 parents 9082d6a + af18962 commit 7f14258

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ let package = Package(
88
.library(
99
name: "SmoothGradient",
1010
targets: ["SmoothGradient"]),
11+
.library(
12+
name: "SmoothGradientDynamic",
13+
type: .dynamic,
14+
targets: ["SmoothGradient"]),
1115
],
1216
targets: [
1317
.target(

Sources/SmoothGradient/SmoothGradientGenerator.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ public enum SmoothGradientInterpolation {
66
}
77

88
/// 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+
}
1527
}
1628

1729
protocol RGBColorConvertible {
@@ -35,7 +47,7 @@ public struct SmoothGradientGenerator {
3547
interpolation: SmoothGradientInterpolation = .hcl,
3648
precision: SmoothGradientPrecision = .medium
3749
) -> [RGBColor] {
38-
let count = precision.rawValue
50+
let count = precision.precisionToCount()
3951
return interpolate(from: from, to: to, count: count, interpolation: interpolation)
4052
}
4153

@@ -68,7 +80,7 @@ public struct SmoothGradientGenerator {
6880
) -> [LCHColor] {
6981
switch interpolation {
7082
case .hcl:
71-
let count = precision.rawValue
83+
let count = precision.precisionToCount()
7284
return interpolate(from: from, to: to, count: count)
7385
default:
7486
return generateAsRGBColor(
@@ -93,7 +105,7 @@ public struct SmoothGradientGenerator {
93105
) -> [HSLColor] {
94106
switch interpolation {
95107
case .hsl:
96-
let count = precision.rawValue
108+
let count = precision.precisionToCount()
97109
return interpolate(from: from, to: to, count: count)
98110
default:
99111
return generateAsRGBColor(
@@ -118,7 +130,7 @@ public struct SmoothGradientGenerator {
118130
) -> [HSBColor] {
119131
switch interpolation {
120132
case .hsb:
121-
let count = precision.rawValue
133+
let count = precision.precisionToCount()
122134
return interpolate(from: from, to: to, count: count)
123135
default:
124136
return generateAsRGBColor(

0 commit comments

Comments
 (0)