Skip to content

Instantly share code, notes, and snippets.

@alladinian
Created March 23, 2020 21:19
Show Gist options
  • Save alladinian/e28cf9f60500df44386897fe91275d41 to your computer and use it in GitHub Desktop.
Save alladinian/e28cf9f60500df44386897fe91275d41 to your computer and use it in GitHub Desktop.
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