CGPoint.swift 684 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // CGPoint.swift
  3. // Naterade
  4. //
  5. // Created by Nathan Racklyeft on 2/29/16.
  6. // Copyright © 2016 Nathan Racklyeft. All rights reserved.
  7. //
  8. import UIKit
  9. extension CGPoint {
  10. /**
  11. Rounds the coordinates to whole-pixel values
  12. - parameter scale: The display scale to use. Defaults to the main screen scale.
  13. */
  14. mutating func makeIntegralInPlaceWithDisplayScale(_ scale: CGFloat = 0) {
  15. var scale = scale
  16. // It's possible for scale values retrieved from traitCollection objects to be 0.
  17. if scale == 0 {
  18. scale = UIScreen.main.scale
  19. }
  20. x = round(x * scale) / scale
  21. y = round(y * scale) / scale
  22. }
  23. }