Skip to content

Instantly share code, notes, and snippets.

@mattt
Created December 26, 2014 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattt/fb9e595e001ca4653e96 to your computer and use it in GitHub Desktop.
Save mattt/fb9e595e001ca4653e96 to your computer and use it in GitHub Desktop.
import CoreGraphics
infix operator |> { precedence 50 associativity left }
// MARK: CGPoint
func +(lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
}
func -(lhs: CGPoint, rhs: CGPoint) -> CGPoint {
return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
}
func |>(lhs: CGPoint, rhs: CGAffineTransform) -> CGPoint {
return CGPointApplyAffineTransform(lhs, rhs)
}
// MARK: CGSize
func *(lhs: CGSize, rhs: CGFloat) -> CGSize {
return CGSize(width: lhs.width * rhs, height: lhs.height * rhs)
}
func /(lhs: CGSize, rhs: CGFloat) -> CGSize {
return CGSize(width: lhs.width / rhs, height: lhs.height / rhs)
}
func |>(lhs: CGSize, rhs: CGAffineTransform) -> CGSize {
return CGSizeApplyAffineTransform(lhs, rhs)
}
// MARK: CGRect
func |(lhs: CGRect, rhs: CGRect) -> CGRect {
return CGRectUnion(lhs, rhs)
}
func &(lhs: CGRect, rhs: CGRect) -> CGRect {
return CGRectIntersection(lhs, rhs)
}
func /(lhs: CGRect, rhs: (amount: CGFloat, edge: CGRectEdge)) -> (slice: CGRect, remainder: CGRect) {
return lhs.rectsByDividing(rhs.amount, fromEdge: rhs.edge)
}
func *(lhs: CGRect, rhs: CGFloat) -> CGRect {
return CGRect(origin: lhs.origin, size: lhs.size * rhs)
}
func |>(lhs: CGRect, rhs: CGAffineTransform) -> CGRect {
return CGRectApplyAffineTransform(lhs, rhs)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment