1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import UIKit
- extension CGPoint {
- public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
- return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
- }
-
- public static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
- return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
- }
-
- public static func * (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
- return CGPoint(x: lhs.x * rhs.x, y: lhs.y * rhs.y)
- }
-
- public static func / (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
- return CGPoint(x: lhs.x / rhs.x, y: lhs.y / rhs.y)
- }
-
- public static func += (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
- return lhs + rhs
- }
-
- public static func -= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
- return lhs - rhs
- }
-
- public static func *= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
- return lhs * rhs
- }
-
- public static func /= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
- return lhs / rhs
- }
-
- public func distance(to target: CGPoint) -> CGFloat {
- return sqrt(pow(self.x - target.x, 2) + pow(self.y - target.y, 2))
- }
-
- public static func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
- return lhs.x == rhs.x && lhs.y == rhs.y
- }
-
- }
|