Skip to content

Commit

Permalink
PZBaseKit // Compiler optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikiSuen committed Nov 7, 2024
1 parent a93d6b3 commit d509af7
Showing 1 changed file with 11 additions and 30 deletions.
41 changes: 11 additions & 30 deletions Packages/PZKit/Sources/PZBaseKit/OSImpl/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public typealias UIColor = NSColor
#endif

extension UIColor {
#if !canImport(UIKit) && canImport(AppKit)
public func modified(
withAdditionalHue hue: CGFloat,
additionalSaturation: CGFloat,
Expand All @@ -22,48 +21,30 @@ extension UIColor {
var currentBrigthness: CGFloat = 0.0
var currentAlpha: CGFloat = 0.0

#if !canImport(UIKit) && canImport(AppKit)
getHue(
&currentHue,
saturation: &currentSaturation,
brightness: &currentBrigthness,
alpha: &currentAlpha
)
#else
let isSucceeded: Bool = getHue(
&currentHue,
saturation: &currentSaturation,
brightness: &currentBrigthness,
alpha: &currentAlpha
)
guard isSucceeded else { return self }
#endif

return UIColor(
hue: currentHue + hue,
saturation: currentSaturation + additionalSaturation,
brightness: currentBrigthness + additionalBrightness,
alpha: currentAlpha
)
}
#else
public func modified(
withAdditionalHue hue: CGFloat,
additionalSaturation: CGFloat,
additionalBrightness: CGFloat
)
-> UIColor {
var currentHue: CGFloat = 0.0
var currentSaturation: CGFloat = 0.0
var currentBrigthness: CGFloat = 0.0
var currentAlpha: CGFloat = 0.0

if getHue(
&currentHue,
saturation: &currentSaturation,
brightness: &currentBrigthness,
alpha: &currentAlpha
) {
return UIColor(
hue: currentHue + hue,
saturation: currentSaturation + additionalSaturation,
brightness: currentBrigthness + additionalBrightness,
alpha: currentAlpha
)
} else {
return self
}
}
#endif
}

#if !canImport(UIKit) && canImport(AppKit)
Expand Down

0 comments on commit d509af7

Please sign in to comment.