No Description

CGPointExt.swift 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // CGPointExt.swift
  3. // ExtensionKit
  4. //
  5. // Created by FFIB on 2017/9/13.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. extension CGPoint {
  10. public static func + (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
  11. return CGPoint(x: lhs.x + rhs.x, y: lhs.y + rhs.y)
  12. }
  13. public static func - (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
  14. return CGPoint(x: lhs.x - rhs.x, y: lhs.y - rhs.y)
  15. }
  16. public static func * (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
  17. return CGPoint(x: lhs.x * rhs.x, y: lhs.y * rhs.y)
  18. }
  19. public static func / (lhs: CGPoint, rhs: CGPoint) -> CGPoint {
  20. return CGPoint(x: lhs.x / rhs.x, y: lhs.y / rhs.y)
  21. }
  22. public static func += (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
  23. return lhs + rhs
  24. }
  25. public static func -= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
  26. return lhs - rhs
  27. }
  28. public static func *= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
  29. return lhs * rhs
  30. }
  31. public static func /= (lhs:CGPoint, rhs: CGPoint) -> CGPoint {
  32. return lhs / rhs
  33. }
  34. public func distance(to target: CGPoint) -> CGFloat {
  35. return sqrt(pow(self.x - target.x, 2) + pow(self.y - target.y, 2))
  36. }
  37. public static func == (lhs: CGPoint, rhs: CGPoint) -> Bool {
  38. return lhs.x == rhs.x && lhs.y == rhs.y
  39. }
  40. }