Skip to content

Instantly share code, notes, and snippets.

@romainmenke
Created October 4, 2015 02:39
Show Gist options
  • Save romainmenke/cbd8f10038b72dfb281c to your computer and use it in GitHub Desktop.
Save romainmenke/cbd8f10038b72dfb281c to your computer and use it in GitHub Desktop.
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