Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.