From 0aa49bc4a9b3d9a7d74fc07429a1d5d2b9a6d2dc Mon Sep 17 00:00:00 2001 From: Yingtao Guo Date: Thu, 25 Apr 2024 22:08:26 -0400 Subject: [PATCH 1/3] fix: fix undo redo rotation issues when flipped --- Sources/Mantis/CropView/CropView.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sources/Mantis/CropView/CropView.swift b/Sources/Mantis/CropView/CropView.swift index 6fceb4bd..bca16845 100644 --- a/Sources/Mantis/CropView/CropView.swift +++ b/Sources/Mantis/CropView/CropView.swift @@ -978,12 +978,19 @@ extension CropView: CropViewProtocol { var newTransform = getTransformInfo(byTransformInfo: cropState.transformation) + func getRotationWhenFlipped() -> CGFloat { + let localRotation = newTransform.rotation.truncatingRemainder(dividingBy: .pi/2) + let rotation90s = newTransform.rotation - localRotation + + return -rotation90s + localRotation + } + if viewModel.horizontallyFlip { - newTransform.rotation = -newTransform.rotation + newTransform.rotation = getRotationWhenFlipped() } if viewModel.verticallyFlip { - newTransform.rotation = -newTransform.rotation + newTransform.rotation = getRotationWhenFlipped() } if newTransform.maskFrame != .zero { From aad3aa680cbf59adb3a93542da21b17a44e518fe Mon Sep 17 00:00:00 2001 From: Yingtao Guo Date: Thu, 25 Apr 2024 22:30:15 -0400 Subject: [PATCH 2/3] fix: update the condition logic for updating newTransform's rotation when flipped --- Sources/Mantis/CropView/CropView.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Sources/Mantis/CropView/CropView.swift b/Sources/Mantis/CropView/CropView.swift index bca16845..3ea231af 100644 --- a/Sources/Mantis/CropView/CropView.swift +++ b/Sources/Mantis/CropView/CropView.swift @@ -985,11 +985,7 @@ extension CropView: CropViewProtocol { return -rotation90s + localRotation } - if viewModel.horizontallyFlip { - newTransform.rotation = getRotationWhenFlipped() - } - - if viewModel.verticallyFlip { + if flipOddTimes { newTransform.rotation = getRotationWhenFlipped() } From ed8bc33b5206a2743e12b4923f2543e8fbb89fe2 Mon Sep 17 00:00:00 2001 From: Yingtao Guo Date: Thu, 25 Apr 2024 22:32:45 -0400 Subject: [PATCH 3/3] refactor: remove local function getRotationWhenFlipped() --- Sources/Mantis/CropView/CropView.swift | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Sources/Mantis/CropView/CropView.swift b/Sources/Mantis/CropView/CropView.swift index 3ea231af..16623a97 100644 --- a/Sources/Mantis/CropView/CropView.swift +++ b/Sources/Mantis/CropView/CropView.swift @@ -978,15 +978,10 @@ extension CropView: CropViewProtocol { var newTransform = getTransformInfo(byTransformInfo: cropState.transformation) - func getRotationWhenFlipped() -> CGFloat { + if flipOddTimes { let localRotation = newTransform.rotation.truncatingRemainder(dividingBy: .pi/2) let rotation90s = newTransform.rotation - localRotation - - return -rotation90s + localRotation - } - - if flipOddTimes { - newTransform.rotation = getRotationWhenFlipped() + newTransform.rotation = -rotation90s + localRotation } if newTransform.maskFrame != .zero {