Skip to content

Commit

Permalink
fix: fix undo redo rotation issues when flipped (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyingtao authored Apr 26, 2024
1 parent 2ad6323 commit 29b6fec
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions Sources/Mantis/CropView/CropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -978,12 +978,10 @@ extension CropView: CropViewProtocol {

var newTransform = getTransformInfo(byTransformInfo: cropState.transformation)

if viewModel.horizontallyFlip {
newTransform.rotation = -newTransform.rotation
}

if viewModel.verticallyFlip {
newTransform.rotation = -newTransform.rotation
if flipOddTimes {
let localRotation = newTransform.rotation.truncatingRemainder(dividingBy: .pi/2)
let rotation90s = newTransform.rotation - localRotation
newTransform.rotation = -rotation90s + localRotation
}

if newTransform.maskFrame != .zero {
Expand Down

3 comments on commit 29b6fec

@rahul6350
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @guoyingtao enum ImageRotationType: CGFloat {
case none = 0
case counterclockwise90 = -90
case counterclockwise180 = -180
case counterclockwise270 = -270

mutating func counterclockwiseRotate90() {
    if self == .counterclockwise270 {
        self = .none
    } else {
        self = ImageRotationType(rawValue: self.rawValue - 90) ?? .none
    }
}

mutating func clockwiseRotate90() {
    switch self {
    case .counterclockwise90:
        self = .none
    case .counterclockwise180:
        self = .counterclockwise90
    case .counterclockwise270:
        self = .counterclockwise180
    case .none:
        self = .counterclockwise270
    }
}

var isRotatedByMultiple180: Bool {
    return self == .none || self == .counterclockwise180
}

} THISis the rotation clockwise and anticlockwise writtent but when i rotate clockwise and anticlockwise image one time two time , suppose rotate two time clockwise give 270 degree i dont know why it gives 180 due to which api fail as paas angle in param i think rotation not working properly give wrong angle can you help me out for this

@rahul6350
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahul6350
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please provide seudo code so i can find every time correct rotation on rotate clockwise and anticlockwise

Please sign in to comment.