Skip to content

Commit

Permalink
lottie: fix interpolation issue
Browse files Browse the repository at this point in the history
Interpolation between closed and open curves
is allowed. Since these curves have a different
number of points, this caused an error. The current
behavior enforces both curves to be treated as opened.

@issue: #2287
  • Loading branch information
mgrudzinska committed May 24, 2024
1 parent 178cf29 commit 160709c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/loaders/lottie/tvgLottieProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,24 +560,26 @@ struct LottiePathSet : LottieProperty

auto s = frame->value.pts;
auto e = (frame + 1)->value.pts;
//possible interpolation between closed and opened curves
auto minFrame = frame->value.ptsCnt <= (frame + 1)->value.ptsCnt ? frame : frame + 1;

if (roundness > ROUNDNESS_EPSILON) {
auto interpPts = (Point*)malloc(frame->value.ptsCnt * sizeof(Point));
auto interpPts = (Point*)malloc(minFrame->value.ptsCnt * sizeof(Point));
auto p = interpPts;
for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e, ++p) {
for (auto i = 0; i < minFrame->value.ptsCnt; ++i, ++s, ++e, ++p) {
*p = mathLerp(*s, *e, t);
if (transform) mathMultiply(p, transform);
}
_modifier(interpPts, frame->value.ptsCnt, frame->value.cmds, frame->value.cmdsCnt, cmds, pts, nullptr, roundness);
_modifier(interpPts, minFrame->value.ptsCnt, minFrame->value.cmds, minFrame->value.cmdsCnt, cmds, pts, nullptr, roundness);
free(interpPts);
return true;
} else {
for (auto i = 0; i < frame->value.ptsCnt; ++i, ++s, ++e) {
for (auto i = 0; i < minFrame->value.ptsCnt; ++i, ++s, ++e) {
auto pt = mathLerp(*s, *e, t);
if (transform) mathMultiply(&pt, transform);
pts.push(pt);
}
_copy(&frame->value, cmds);
_copy(&minFrame->value, cmds);
}
return true;
}
Expand Down

0 comments on commit 160709c

Please sign in to comment.