Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. let filter = CIFilter(name: "CIPerspectiveCorrection")!
  2. let width = CGFloat(image.size.width)
  3. let height = CGFloat(image.size.height)
  4. var topLeft = CGPoint(x: rectangle.topLeft.x * width, y: rectangle.topLeft.y * height)
  5. var topRight = CGPoint(x: rectangle.topRight.x * width, y: rectangle.topRight.y * height)
  6. var bottomLeft = CGPoint(x: rectangle.bottomLeft.x * width, y: rectangle.bottomLeft.y * height)
  7. var bottomRight = CGPoint(x: rectangle.bottomRight.x * width, y: rectangle.bottomRight.y * height)
  8.  
  9. let scaleH = height/width
  10. print(width)
  11. print(height)
  12. print(topLeft)
  13. print(topRight)
  14. print(bottomLeft)
  15. print(bottomRight)
  16. func checkRectangle() -> Bool{
  17. var returnValue = true
  18. if topRight.y > height - scaleH{
  19. returnValue = false
  20. }
  21. if topLeft.y > height - scaleH{
  22. returnValue = false
  23. }
  24. if bottomLeft.y < scaleH{
  25. returnValue = false
  26. }
  27. if bottomRight.y < scaleH{
  28. returnValue = false
  29. }
  30.  
  31. if topRight.x > width - 1{
  32. returnValue = false
  33. }
  34. if topLeft.x < 1{
  35. returnValue = false
  36. }
  37. if bottomLeft.x < 1{
  38. returnValue = false
  39. }
  40. if bottomRight.x > width - 1{
  41. returnValue = false
  42. }
  43. return returnValue
  44. }
  45.  
  46. repeat{
  47. topLeft.y += scaleH
  48. topLeft.x -= 1
  49.  
  50. topRight.y += scaleH
  51. topRight.x += 1
  52.  
  53. bottomRight.y -= scaleH
  54. bottomRight.x += 1
  55.  
  56. bottomLeft.y -= scaleH
  57. bottomLeft.x -= 1
  58.  
  59. }while(checkRectangle())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement