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

Fixed accuracy in some cases #42

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

sampad1370
Copy link

@sampad1370 sampad1370 commented Apr 5, 2024

Also, it's improved with removing dividing and multiplying with "total" in every step.

It will be fixed incorrect result in the following example:

auto tween = tweeny::from(1.0f, 1.0f)
.to(7.0f, 7.0f)
.during(60)
.via(tweeny::easing::enumerated::linear)
.onStep([](float i, float f) {
printf("running: i=%f f=%f\n", i, f);
fflush(stdout);
return false;
});
while (tween.progress() < 1.0f) {
auto [value1, value2] = tween.peek(tween.progress());
printf(" progress:%f and values is: %f,%f\n", tween.progress(), value1, value2);
fflush(stdout);
tween.step(10);
}
fflush(stdout);
tween.backward();
while (tween.progress() > 0.0f) {
auto [value1, value2] = tween.peek(tween.progress());
printf(" progress:%f and values is: %f,%f\n", tween.progress(), value1, value2);
fflush(stdout);
tween.step(10);
}
auto [value1, value2] = tween.peek(tween.progress());
printf(" progress:%f and values is: %f,%f\n", tween.progress(), value1, value2);

I get following result on Ubuntu 22.04 with gcc-11 without this commit:

progress:0.000000 and values is: 1.000000,1.000000
running: i=2.000000 f=2.000000
progress:0.166667 and values is: 2.000000,2.000000
running: i=3.000000 f=3.000000
progress:0.333333 and values is: 3.000000,3.000000
running: i=4.000000 f=4.000000
progress:0.500000 and values is: 4.000000,4.000000
running: i=5.000000 f=5.000000
progress:0.666667 and values is: 5.000000,5.000000
running: i=6.000000 f=6.000000
progress:0.833333 and values is: 6.000000,6.000000
running: i=7.000000 f=7.000000
progress:1.000000 and values is: 7.000000,7.000000
running: i=6.000000 f=6.000000
progress:0.833333 and values is: 6.000000,6.000000
running: i=4.900000 f=4.900000
progress:0.666667 and values is: 4.900000,4.900000
running: i=3.900000 f=3.900000
progress:0.500000 and values is: 3.900000,3.900000
running: i=2.900000 f=2.900000
progress:0.333333 and values is: 2.900000,2.900000
running: i=1.900000 f=1.900000
progress:0.166667 and values is: 1.900000,1.900000
running: i=1.000000 f=1.000000
progress:0.000000 and values is: 1.000000,1.000000

but it must be:

progress:0.000000 and values is: 1.000000,1.000000
running: i=2.000000 f=2.000000
progress:0.166667 and values is: 2.000000,2.000000
running: i=3.000000 f=3.000000
progress:0.333333 and values is: 3.000000,3.000000
running: i=4.000000 f=4.000000
progress:0.500000 and values is: 4.000000,4.000000
running: i=5.000000 f=5.000000
progress:0.666667 and values is: 5.000000,5.000000
running: i=6.000000 f=6.000000
progress:0.833333 and values is: 6.000000,6.000000
running: i=7.000000 f=7.000000
progress:1.000000 and values is: 7.000000,7.000000
running: i=6.000000 f=6.000000
progress:0.833333 and values is: 6.000000,6.000000
running: i=5.000000 f=5.000000
progress:0.666667 and values is: 5.000000,5.000000
running: i=4.000000 f=4.000000
progress:0.500000 and values is: 4.000000,4.000000
running: i=3.000000 f=3.000000
progress:0.333333 and values is: 3.000000,3.000000
running: i=2.000000 f=2.000000
progress:0.166667 and values is: 2.000000,2.000000
running: i=1.000000 f=1.000000
progress:0.000000 and values is: 1.000000,1.000000

The result of direct stepping and backward stepping is different! And I think there are many similar cases. And I think extra divining and multiplying can be removed.
Please check my commit.

Copy link
Owner

@mobius3 mobius3 left a comment

Choose a reason for hiding this comment

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

Thanks! This is very nice and I'm willing to accept it, but there are some unrelated edits, mostly in regards to formatting, that I don't think are justifiable for what this PR does (it's even harder to review because of that). I was going to point it out directly at each inconsistency but I suggest, at least for this PR, turning off code formatting in your IDE, reverting the code to what it was previously and performing your changes again, without breaking code style.

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.

2 participants