Transformable.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // Extendable.swift
  3. // WeScan
  4. //
  5. // Created by Boris Emorine on 2/15/18.
  6. // Copyright © 2018 WeTransfer. All rights reserved.
  7. //
  8. import Foundation
  9. /// Objects that conform to the Transformable protocol are capable of being transformed with a `CGAffineTransform`.
  10. protocol Transformable {
  11. /// Applies the given `CGAffineTransform`.
  12. ///
  13. /// - Parameters:
  14. /// - t: The transform to apply
  15. /// - Returns: The same object transformed by the passed in `CGAffineTransform`.
  16. func applying(_ transform: CGAffineTransform) -> Self
  17. }
  18. extension Transformable {
  19. /// Applies multiple given transforms in the given order.
  20. ///
  21. /// - Parameters:
  22. /// - transforms: The transforms to apply.
  23. /// - Returns: The same object transformed by the passed in `CGAffineTransform`s.
  24. func applyTransforms(_ transforms: [CGAffineTransform]) -> Self {
  25. var transformableObject = self
  26. transforms.forEach { (transform) in
  27. transformableObject = transformableObject.applying(transform)
  28. }
  29. return transformableObject
  30. }
  31. }