Skip to content

Commit

Permalink
Merge pull request #3 from BeehiveInnovations/main
Browse files Browse the repository at this point in the history
dynamic library support + custom precision
  • Loading branch information
intitni authored Jan 17, 2022
2 parents 9082d6a + af18962 commit 7f14258
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ let package = Package(
.library(
name: "SmoothGradient",
targets: ["SmoothGradient"]),
.library(
name: "SmoothGradientDynamic",
type: .dynamic,
targets: ["SmoothGradient"]),
],
targets: [
.target(
Expand Down
32 changes: 22 additions & 10 deletions Sources/SmoothGradient/SmoothGradientGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,24 @@ public enum SmoothGradientInterpolation {
}

/// Define the number of intermediate colors to generate.
public enum SmoothGradientPrecision: Int {
case low = 1
case lowMedium = 3
case medium = 5
case mediumHigh = 7
case high = 9
public enum SmoothGradientPrecision {
case low
case lowMedium
case medium
case mediumHigh
case high
case custom(Int)

func precisionToCount() -> Int {
switch self {
case .low: return 1
case .lowMedium: return 3
case .medium: return 5
case .mediumHigh: return 7
case .high: return 9
case .custom(let value): return value
}
}
}

protocol RGBColorConvertible {
Expand All @@ -35,7 +47,7 @@ public struct SmoothGradientGenerator {
interpolation: SmoothGradientInterpolation = .hcl,
precision: SmoothGradientPrecision = .medium
) -> [RGBColor] {
let count = precision.rawValue
let count = precision.precisionToCount()
return interpolate(from: from, to: to, count: count, interpolation: interpolation)
}

Expand Down Expand Up @@ -68,7 +80,7 @@ public struct SmoothGradientGenerator {
) -> [LCHColor] {
switch interpolation {
case .hcl:
let count = precision.rawValue
let count = precision.precisionToCount()
return interpolate(from: from, to: to, count: count)
default:
return generateAsRGBColor(
Expand All @@ -93,7 +105,7 @@ public struct SmoothGradientGenerator {
) -> [HSLColor] {
switch interpolation {
case .hsl:
let count = precision.rawValue
let count = precision.precisionToCount()
return interpolate(from: from, to: to, count: count)
default:
return generateAsRGBColor(
Expand All @@ -118,7 +130,7 @@ public struct SmoothGradientGenerator {
) -> [HSBColor] {
switch interpolation {
case .hsb:
let count = precision.rawValue
let count = precision.precisionToCount()
return interpolate(from: from, to: to, count: count)
default:
return generateAsRGBColor(
Expand Down

0 comments on commit 7f14258

Please sign in to comment.