Created
October 29, 2019 09:30
-
-
Save ole/ae0c791030ed44aade9a823edf0a6aeb to your computer and use it in GitHub Desktop.
Using × as a custom operator for creating "x-by-y" values such as CGPoint or CGSize.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precedencegroup XByYPrecedence { | |
associativity: left | |
higherThan: MultiplicationPrecedence | |
} | |
infix operator ×: XByYPrecedence // U+00D7 MULTIPLICATION SIGN | |
// ------ | |
import CoreGraphics | |
func × (x: CGFloat, y: CGFloat) -> CGPoint { | |
CGPoint(x: x, y: y) | |
} | |
func × (width: CGFloat, height: CGFloat) -> CGSize { | |
CGSize(width: width, height: height) | |
} | |
let point: CGPoint = 100×80 | |
let size: CGSize = 800×600 | |
// ------ | |
import UIKit | |
let image = UIGraphicsImageRenderer(size: 320×240).image { context in | |
UIColor.yellow.setFill() | |
UIRectFill(CGRect(origin: 20×20, size: 280×200)) | |
} | |
// ------ | |
import SceneKit | |
func × (xy: CGPoint, z: CGFloat) -> SCNVector3 { | |
SCNVector3(xy.x, xy.y, z) | |
} | |
let point3D: SCNVector3 = 10×20×30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment