Created
March 23, 2020 21:19
-
-
Save alladinian/e28cf9f60500df44386897fe91275d41 to your computer and use it in GitHub Desktop.
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
import Foundation | |
// Just for clarity of intention | |
typealias AbsolutePoint = CGPoint | |
typealias RelativePoint = CGPoint | |
func * (lhs: CGSize, rhs: CGSize) -> CGSize { | |
.init(width: lhs.width * rhs.width, height: lhs.height * rhs.height) | |
} | |
func * (lhs: CGPoint, rhs: CGSize) -> CGPoint { | |
.init(x: lhs.x * rhs.width, y: lhs.y * rhs.height) | |
} | |
func - (lhs: CGPoint, rhs: CGFloat) -> CGPoint { | |
.init(x: lhs.x - rhs, y: lhs.y - rhs) | |
} | |
func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint { | |
.init(x: lhs.x + rhs.x, y: lhs.y + rhs.y) | |
} | |
func + (lhs: CGSize, rhs: CGSize) -> CGSize { | |
.init(width: lhs.width + rhs.width, height: lhs.height + rhs.height) | |
} | |
func / (lhs: CGSize, rhs: CGSize) -> CGSize { | |
.init(width: lhs.width / rhs.width, height: lhs.height / rhs.height) | |
} | |
extension CGSize { | |
var toPoint: CGPoint { .init(x: width, y: height) } | |
var half: CGSize { .init(width: width/2, height: height/2) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment