Created
October 4, 2015 02:39
-
-
Save romainmenke/cbd8f10038b72dfb281c 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
protocol CGRectExpand { | |
var origin : CGPoint { get set } | |
var size : CGSize { get set } | |
mutating func expand(amount amount_I: CGFloat) | |
} | |
extension CGRectExpand { | |
mutating func expand(amount amount_I:CGFloat) { | |
var amount : CGFloat = amount_I | |
if (amount_I * 2) < -size.width || (amount_I * 2) < -size.height { | |
amount = (max(-size.width, -size.height)) / 2 | |
} | |
origin.x = origin.x - amount | |
origin.y = origin.y - amount | |
size.width = size.width + (amount * 2) | |
size.height = size.height + (amount * 2) | |
} | |
} | |
extension CGRect: CGRectExpand { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment