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

fix(interpolation): fix bezier interpolation between same values #2841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stepancar
Copy link
Contributor

@stepancar stepancar commented Aug 26, 2022

I've reported issue #2840

This PR solves this value.
Change is pretty small but maybe not obvious why it is legal here to multiply curve value with 1.

So, as we know according lottie docs keyframe describes easing handling (cubic bezier) between current keyframe and next keyframe values.
It contains 2 base points with coordinates [0,0] [1,1], and control points are stored in in, out properties.

This is regular example how it can look like https://cubic-bezier.com/#.2,1.44,.7,.31
Let's say we are animating between values [10, 20]
It's easy to interpolate.

const newVal = currentKeyframe.s[i] + (nextKeyframe.s[i] - currentKeyframe.s[i]) * curve.getValue(percentage);

// (nextKeyframe.s[i] - currentKeyframe.s[i]) * curve.getValue(percentage) - describes increment

And it's obvious that when percentage is 100 newVal is

const newVal = currentKeyframe.s[i] + (nextKeyframe.s[i] - currentKeyframe.s[i]) * 1; // => 
const newVal = nextKeyframe.s[i];

which make sense;

In our case we are interpolating between same value;
which actually means that [1,1] point is equal to [1,0] point because there is no difference between values.
In this case curve describes increment itself.

@bodymovin
Copy link
Collaborator

bodymovin commented Sep 5, 2022

Hi thanks for the PR. So if I'm understanding this change correctly, it is adding the percentage value to the initial value of the segment when start and end match. But a percentage is within the range of 0-1, so adding that value will not return the correct result.
Unfortunately, finding the right solution for this type of case has been very hard to achieve.

@stepancar
Copy link
Contributor Author

stepancar commented Sep 6, 2022

@bodymovin , let me recheck, our implementation of interpolation is a little bit different. Maybe I made mistake.

@bodymovin
perc is a result of BezierFactory.getBezierEasing(...).get
call. This value is not always between 0 and 1.

You can check it

var bezier = BezierFactory.getBezierEasing(0,3,0.5,4);
bezier.get(0.5)

When difference between keyframes is zero, you can see that y value of control point inside lottie is a big value.

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

4 participants