Last active
September 29, 2016 16:56
-
-
Save alekseypotapov-dev/ac5f737145fa994fdefa18550d47e141 to your computer and use it in GitHub Desktop.
CoreGraphics methods override
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
//Copyright | |
//https://habrahabr.ru/post/271647/ | |
import Foundation | |
// Summ and Substraction of Vectors | |
func +(left: CGPoint, right: CGPoint)->CGPoint{ | |
return CGPoint(x: left.x+right.x, y: left.y+right.y) | |
} | |
prefix func -(right: CGPoint)->CGPoint{ | |
return CGPoint(x: -right.x, y: -right.y) | |
} | |
func -(left: CGPoint, right: CGPoint)->CGPoint{ | |
return left + (-right) | |
} | |
/////////////////////////////////////////////////// | |
//Multiplication and division of Vectors to Scalar | |
func *(left: CGPoint, right: CGFloat)->CGPoint{ | |
return CGPoint(x: left.x*right, y: left.y*right) | |
} | |
func *(left: CGFloat, right: CGPoint)->CGPoint{ | |
return right*left | |
} | |
func /(left: CGPoint, right: CGFloat)->CGPoint{ | |
return left*(1/right) | |
} | |
/////////////////////////////////////////////////// | |
func +=(inout left:CGPoint, right:CGPoint){ | |
left = left+right | |
} | |
func -=(inout left:CGPoint, right:CGPoint){ | |
left = left-right | |
} | |
func *=(inout left:CGPoint, right:CGFloat){ | |
left = left*right | |
} | |
func /=(inout left:CGPoint, right:CGFloat){ | |
left = left/right | |
} | |
/////////////////////////////////////////////////// | |
/////////////////////////////////////////////////// | |
func *(left: CGPoint, right: CGPoint)->CGFloat{ | |
return left.x*right.x + left.y*right.y | |
} | |
func /(left: CGPoint, right: CGPoint)->CGFloat{ | |
return left.x*right.y - left.y*right.x | |
} | |
/////////////////////////////////////////////////// | |
/////////////////////////////////////////////////// | |
func *(left: CGPoint, right: CGAffineTransform)->CGPoint{ | |
return CGPointApplyAffineTransform(left, right) | |
} | |
func *=(inout left:CGPoint, right:CGAffineTransform){ | |
left = left*right | |
} | |
/////////////////////////////////////////////////// | |
func *(left: CGAffineTransform, right: CGAffineTransform)->CGAffineTransform{ | |
return CGAffineTransformConcat(left, right) | |
} | |
func *=(inout left:CGAffineTransform, right:CGAffineTransform){ | |
left = left*right | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment