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

RotateGestureDetector getRotationDegreesDelta returns values close to 360 on small angle change #36

Open
stanleyguevara opened this issue Jul 16, 2019 · 0 comments

Comments

@stanleyguevara
Copy link

Performing minuscule rotations while having rotation line between fingers horizontal causes to getRotationDegreesDelta to output values close to 360, e.g. -359.4 or 359.2.

This is caused by Math.atan2 used to calculate diff angle having ambiguity around +-180*. All is fine and well when performed rotation is shown 1:1 on screen, but I'm scaling it to get more precise moment with small values, so when the received values are 0.015, 0.020, 0.017, -359.4, 0.021... it causes a sudden jerk.

IMO it's a bug because nobody expects sudden 360 for minuscule finger motion when calling getRotationDegreesDelta. The real change of angle is certainly NOT a 360 degree.

My workaround was:

val raw = detector.rotationDegreesDelta
val diffRotation = if (abs(raw) > 300) {   // or some other arbitrary value above 180*
    if (raw < 0) {
        360 + raw
    } else {
        raw - 360
    }
} else raw

I think better fix (without arbitrary 300* value) can be done on library side by checking if one angle falls close to 180* and other close to -180*, so it's passing through discontinous part of Math.atan2 and can be accounted for.

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

No branches or pull requests

1 participant