Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes counter-clockwise rotation #207

Merged
merged 1 commit into from
Nov 29, 2016
Merged

Conversation

timothylcooke
Copy link
Contributor

When you specify CropImageOptions.allowCounterRotation = true, the crop_image_menu_rotate_left MenuItem is shown. When it is selected, the code rotateImage(-mOptions.rotationDegrees); is executed. Yet the rotateImage method expected a value between 0 and 360. This creates unexpected behavior when one rotates an image counter-clockwise and the image's crop rectangle is not a square, or when CropImageOptions.rotationDegrees is set to an unusual value, such as 450 or -90.

I've fixed the CropImageView.rotateImage(int) method. At the beginning of the method, I ensure that the degrees parameter be in the range [0, 360]. Now, because degrees is always non-negative, I can simplify the computation that changes mDegreesRotated. Additionally, the computation for flipAxes was missing parentheses, so I fixed that as well.

It should be noted that the forcing of the degrees to a non-zero value in the range [0,360) can be simplified to just:

degrees = ((degrees % 360) + 360) % 360;

I left the more verbose if statement to make it more obvious what the code was doing.

Collectively, these changes ensure that the image is correctly rotated, even if the value passed in is outside of the range [0, 360]. This is particularly important for counter-clockwise rotations.

Fixes operator-precedence-related bug in flipAxes computation

Collectively, these changes ensure that the image is correctly rotated, even if the value passed in is outside of the range [0, 360]. This is particularly important for counter-clockwise rotations.
@timothylcooke
Copy link
Contributor Author

In my commit, I added the comment:

// Force degrees to be a non-zero value between 0 and 360 (inclusive)

I meant non-negative, instead of non-zero.

@ArthurHub
Copy link
Owner

looks good, thx!

@ArthurHub ArthurHub merged commit 2f3b9d4 into ArthurHub:master Nov 29, 2016
timothylcooke added a commit to timothylcooke/Android-Image-Cropper that referenced this pull request Dec 2, 2016
Merge pull request ArthurHub#207 from timothylcooke/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants