Skip to content

[CoreGraphics] Make CGColor adopt _ExpressibleByColorLiteral. #9733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 38 additions & 19 deletions stdlib/public/SDK/CoreGraphics/CoreGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import Darwin
// CGAffineTransform
//===----------------------------------------------------------------------===//

extension CGAffineTransform: Equatable {}
public func ==(lhs: CGAffineTransform, rhs: CGAffineTransform) -> Bool {
return lhs.__equalTo(rhs)
extension CGAffineTransform: Equatable {
public static func ==(lhs: CGAffineTransform,
rhs: CGAffineTransform) -> Bool {
return lhs.__equalTo(rhs)
}
}

//===----------------------------------------------------------------------===//
Expand All @@ -46,6 +48,19 @@ extension CGColor {
#endif
}

public protocol _CGColorInitTrampoline {
init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)
}

extension _CGColorInitTrampoline {
public init(colorLiteralRed red: Float, green: Float, blue: Float,
alpha: Float) {
self.init(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue),
alpha: CGFloat(alpha))
}
}

extension CGColor : _CGColorInitTrampoline, _ExpressibleByColorLiteral { }

//===----------------------------------------------------------------------===//
// CGColorSpace
Expand Down Expand Up @@ -228,10 +243,11 @@ extension CGPoint : CustomDebugStringConvertible {
}
}

extension CGPoint : Equatable {}
@_transparent // @fragile
public func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x == rhs.x && lhs.y == rhs.y
extension CGPoint : Equatable {
@_transparent // @fragile
public static func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
return lhs.x == rhs.x && lhs.y == rhs.y
}
}

public extension CGSize {
Expand Down Expand Up @@ -279,10 +295,11 @@ extension CGSize : CustomDebugStringConvertible {
}
}

extension CGSize : Equatable {}
@_transparent // @fragile
public func == (lhs: CGSize, rhs: CGSize) -> Bool {
return lhs.width == rhs.width && lhs.height == rhs.height
extension CGSize : Equatable {
@_transparent // @fragile
public static func == (lhs: CGSize, rhs: CGSize) -> Bool {
return lhs.width == rhs.width && lhs.height == rhs.height
}
}

public extension CGVector {
Expand All @@ -302,10 +319,11 @@ public extension CGVector {
}
}

extension CGVector : Equatable {}
@_transparent // @fragile
public func == (lhs: CGVector, rhs: CGVector) -> Bool {
return lhs.dx == rhs.dx && lhs.dy == rhs.dy
extension CGVector : Equatable {
@_transparent // @fragile
public static func == (lhs: CGVector, rhs: CGVector) -> Bool {
return lhs.dx == rhs.dx && lhs.dy == rhs.dy
}
}

extension CGVector : CustomDebugStringConvertible {
Expand Down Expand Up @@ -380,10 +398,11 @@ extension CGRect : CustomDebugStringConvertible {
}
}

extension CGRect : Equatable {}
@_transparent // @fragile
public func == (lhs: CGRect, rhs: CGRect) -> Bool {
return lhs.equalTo(rhs)
extension CGRect : Equatable {
@_transparent // @fragile
public static func == (lhs: CGRect, rhs: CGRect) -> Bool {
return lhs.equalTo(rhs)
}
}

extension CGAffineTransform {
Expand Down
11 changes: 11 additions & 0 deletions validation-test/stdlib/CoreGraphics-execute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ CoreGraphicsTests.test("CGColor.components") {
expectEqual(components[3], 1)
}

CoreGraphicsTests.test("CGColor/ExpressibleByColorLiteral") {
let colorLit: CGColor = #colorLiteral(red: 0.25, green: 0.5, blue: 0.75,
alpha: 1.0)
let components = colorLit.components!
expectEqual(components.count, 4)
expectEqual(components[0], 0.25)
expectEqual(components[1], 0.50)
expectEqual(components[2], 0.75)
expectEqual(components[3], 1.0)
}

//===----------------------------------------------------------------------===//
// CGPoint
//===----------------------------------------------------------------------===//
Expand Down