Created
March 2, 2018 11:59
-
-
Save eugenebokhan/050b876af12179cd529bcec170a8b732 to your computer and use it in GitHub Desktop.
CGSize extensions
This file contains 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
extension CGSize { | |
init(_ point: CGPoint) { | |
self.width = point.x | |
self.height = point.y | |
} | |
func friendlyString() -> String { | |
return "(\(String(format: "%.2f", width)), \(String(format: "%.2f", height)))" | |
} | |
} | |
func + (left: CGSize, right: CGSize) -> CGSize { | |
return CGSize(width: left.width + right.width, height: left.height + right.height) | |
} | |
func - (left: CGSize, right: CGSize) -> CGSize { | |
return CGSize(width: left.width - right.width, height: left.height - right.height) | |
} | |
func += (left: inout CGSize, right: CGSize) { | |
left = left + right | |
} | |
func -= (left: inout CGSize, right: CGSize) { | |
left = left - right | |
} | |
func / (left: CGSize, right: CGFloat) -> CGSize { | |
return CGSize(width: left.width / right, height: left.height / right) | |
} | |
func * (left: CGSize, right: CGFloat) -> CGSize { | |
return CGSize(width: left.width * right, height: left.height * right) | |
} | |
func /= (left: inout CGSize, right: CGFloat) { | |
left = left / right | |
} | |
func *= (left: inout CGSize, right: CGFloat) { | |
left = left * right | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment