Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
mtynior committed Nov 2, 2016
1 parent b6366c5 commit de46dc4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
13 changes: 10 additions & 3 deletions Felucia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,12 @@
900EE6C21CAFEFF9004AF16A = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = SGZ6FVQB6B;
LastSwiftMigration = 0800;
LastSwiftMigration = 0810;
};
900EE6D41CAFF124004AF16A = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = SGZ6FVQB6B;
LastSwiftMigration = 0810;
};
9061C9231BD5602900A191B7 = {
CreatedOnToolsVersion = 7.1;
Expand Down Expand Up @@ -435,6 +436,7 @@
PRODUCT_NAME = Felucia;
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -458,6 +460,7 @@
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -479,6 +482,7 @@
PRODUCT_NAME = Felucia;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand All @@ -501,6 +505,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -550,7 +555,6 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0.1;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -593,7 +597,6 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0.1;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -617,6 +620,7 @@
PRODUCT_NAME = Felucia;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -636,6 +640,7 @@
PRODUCT_NAME = Felucia;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -646,6 +651,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.tynior.FeluciaTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -657,6 +663,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.tynior.FeluciaTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions FeluciaTests/FeluciaTestsUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension FeluciaTestsUtils {
func test_ColorLightenBy100PercentShouldBecomeWhite() {
let expectedColor = UIColor.white

let lightenColor = UIColor(hexARGB:"#f00")!.lighten(percentage: 1.0)
let lightenColor = UIColor(hexARGB:"#f00")!.lighten(1.0)

let areEqual = expectedColor == lightenColor

Expand All @@ -67,7 +67,7 @@ extension FeluciaTestsUtils {
func test_ColorDarkenBy100PercentShouldBecomeBlack() {
let expectedColor = UIColor.black

let darkenColor = UIColor(hexARGB:"#f00")!.darken(percentage: 1.0)
let darkenColor = UIColor(hexARGB:"#f00")!.darken(1.0)

let areEqual = expectedColor == darkenColor

Expand Down
30 changes: 15 additions & 15 deletions Source/Felucia.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public func != (lhs: UIColor, rhs: UIColor) -> Bool {
extension UIColor {

public convenience init(r: Int, g: Int, b: Int, a: Int = 255) {
let ratioRed = Float(UIColor.clamp(value: r, minValue: 0, maxValue: 255)) / 255.0
let ratioGreen = Float(UIColor.clamp(value: g, minValue: 0, maxValue: 255)) / 255.0
let ratioBlue = Float(UIColor.clamp(value: b, minValue: 0, maxValue: 255)) / 255.0
let ratioAlpha = Float(UIColor.clamp(value: a, minValue: 0, maxValue: 255)) / 255.0
let ratioRed = Float(UIColor.clamp(r, minValue: 0, maxValue: 255)) / 255.0
let ratioGreen = Float(UIColor.clamp(g, minValue: 0, maxValue: 255)) / 255.0
let ratioBlue = Float(UIColor.clamp(b, minValue: 0, maxValue: 255)) / 255.0
let ratioAlpha = Float(UIColor.clamp(a, minValue: 0, maxValue: 255)) / 255.0

self.init(colorLiteralRed: ratioRed, green: ratioGreen, blue: ratioBlue, alpha: ratioAlpha)
}
Expand All @@ -57,7 +57,7 @@ extension UIColor {
return [components.r, components.g, components.b, components.a]
}

private class func clamp(value: Int, minValue: Int, maxValue: Int) -> Int {
fileprivate class func clamp(_ value: Int, minValue: Int, maxValue: Int) -> Int {
return max(minValue, min(value, maxValue))
}
}
Expand All @@ -71,19 +71,19 @@ extension UIColor {
let hex6 = "^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$"
let hex8 = "^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$"

if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex3) {
if let comp = UIColor.getComponents(hexARGB, pattern: hex3) {
let r = Int(comp[0] + comp[0], radix:16)!
let g = Int(comp[1] + comp[1], radix:16)!
let b = Int(comp[2] + comp[2], radix:16)!

self.init(r:r, g:g, b:b)
} else if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex6) {
} else if let comp = UIColor.getComponents(hexARGB, pattern: hex6) {
let r = Int(comp[0], radix:16)!
let g = Int(comp[1], radix:16)!
let b = Int(comp[2], radix:16)!

self.init(r:r, g:g, b:b)
} else if let comp = UIColor.getComponents(hex: hexARGB, pattern: hex8) {
} else if let comp = UIColor.getComponents(hexARGB, pattern: hex8) {
let a = Int(comp[0], radix:16)!
let r = Int(comp[1], radix:16)!
let g = Int(comp[2], radix:16)!
Expand All @@ -100,7 +100,7 @@ extension UIColor {
}
}

private class func getComponents(hex: String, pattern: String) -> [String]? {
fileprivate class func getComponents(_ hex: String, pattern: String) -> [String]? {
let regex = try! NSRegularExpression(pattern: pattern, options: .caseInsensitive)

guard let match = regex.firstMatch(in: hex, options: [], range: NSRange(location: 0, length: hex.characters.count)) else {
Expand Down Expand Up @@ -187,15 +187,15 @@ extension UIColor {
} else {
let q = (normalizedL < 0.5) ? (normalizedL * (1 + normalizedS)) : (normalizedL + normalizedS - normalizedL * normalizedS)
let p = 2 * normalizedL - q
r = UIColor.hue2rgb(p: p, q: q, t1: normalizedH + 1.0/3.0)
g = UIColor.hue2rgb(p: p, q: q, t1: normalizedH)
b = UIColor.hue2rgb(p: p, q: q, t1: normalizedH - 1.0/3.0)
r = UIColor.hue2rgb(p, q: q, t1: normalizedH + 1.0/3.0)
g = UIColor.hue2rgb(p, q: q, t1: normalizedH)
b = UIColor.hue2rgb(p, q: q, t1: normalizedH - 1.0/3.0)
}

self.init(colorLiteralRed: r, green: g, blue: b, alpha: a)
}

class func hue2rgb(p: Float, q: Float, t1: Float) -> Float {
class func hue2rgb(_ p: Float, q: Float, t1: Float) -> Float {
var t = t1
if(t < 0) {t += 1}
if(t > 1) {t -= 1}
Expand Down Expand Up @@ -282,7 +282,7 @@ extension UIColor {

}

public func lighten(percentage: Float = 0.1) -> UIColor {
public func lighten(_ percentage: Float = 0.1) -> UIColor {
var components = hsla()

components.l += percentage
Expand All @@ -291,7 +291,7 @@ extension UIColor {
return UIColor(h: components.h, s: components.s, l: components.l)
}

public func darken(percentage: Float = 0.1) -> UIColor {
public func darken(_ percentage: Float = 0.1) -> UIColor {
var components = hsla()

components.l -= percentage
Expand Down

0 comments on commit de46dc4

Please sign in to comment.