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

Enforce order of operations to avoid rounding errors #1897

Merged
merged 1 commit into from
Sep 19, 2021
Merged

Enforce order of operations to avoid rounding errors #1897

merged 1 commit into from
Sep 19, 2021

Conversation

scottdweber
Copy link
Contributor

Previously, the calculation of endLength could suffer from rounding errors. While most of the time, these errors are not a big deal, when the end value is 100, this can result in endLength being larger than totalLength, causing unexpected behavior where the animation reverts to an initial state when it should be showing the final state. By forcing the order of operations, we can get the answer we expect / need.

For example:

val totalLength = 98.164566
totalLength * 100f / 100f // 98.16457
totalLength * (100f / 100f) // 98.164566

Unfortunately, I have been unable to get a simple animation to reproduce this error, and the complex one I am using is not really available for public sharing. However, it seems like this should be a safe change.

@LottieSnapshotBot
Copy link

Snapshot Tests
28: Report Diff

@scottdweber
Copy link
Contributor Author

scottdweber commented Sep 10, 2021

Oh, nice! Those visual tests show a couple examples of the bug and that it is fixed with this PR 🕺

Copy link
Collaborator

@gpeal gpeal left a comment

Choose a reason for hiding this comment

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

Thanks for catching and fixing this!

@gpeal gpeal changed the title fix: enforce order of operations to avoid rounding errors Enforce order of operations to avoid rounding errors Sep 19, 2021
@gpeal gpeal merged commit 12748d4 into airbnb:master Sep 19, 2021
@scottdweber scottdweber deleted the sweber/fix-stroke-calculation branch September 20, 2021 12:54
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.

4 participants