mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 12:34:30 +00:00
lottie: refactoring key frame logic.
compare floating-point values properly to avoid potential precision loss.
This commit is contained in:
parent
7b56240694
commit
6052407128
1 changed files with 5 additions and 9 deletions
|
@ -362,7 +362,7 @@ struct LottieGenericProperty : LottieProperty
|
||||||
if (frameNo >= frames->last().no) return frames->last().value;
|
if (frameNo >= frames->last().no) return frames->last().value;
|
||||||
|
|
||||||
auto frame = frames->data + _bsearch(frames, frameNo);
|
auto frame = frames->data + _bsearch(frames, frameNo);
|
||||||
if (frame->no == frameNo) return frame->value;
|
if (mathEqual(frame->no, frameNo)) return frame->value;
|
||||||
return frame->interpolate(frame + 1, frameNo);
|
return frame->interpolate(frame + 1, frameNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ struct LottiePathSet : LottieProperty
|
||||||
|
|
||||||
auto frame = frames->data + _bsearch(frames, frameNo);
|
auto frame = frames->data + _bsearch(frames, frameNo);
|
||||||
|
|
||||||
if (frame->no == frameNo) {
|
if (mathEqual(frame->no, frameNo)) {
|
||||||
_copy(frame->value, cmds);
|
_copy(frame->value, cmds);
|
||||||
_copy(frame->value, pts, transform);
|
_copy(frame->value, pts, transform);
|
||||||
return true;
|
return true;
|
||||||
|
@ -601,14 +601,10 @@ struct LottieColorStop : LottieProperty
|
||||||
return fill->colorStops(frames->first().value.data, count);
|
return fill->colorStops(frames->first().value.data, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameNo >= frames->last().no) {
|
if (frameNo >= frames->last().no) return fill->colorStops(frames->last().value.data, count);
|
||||||
return fill->colorStops(frames->last().value.data, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto frame = frames->data + _bsearch(frames, frameNo);
|
auto frame = frames->data + _bsearch(frames, frameNo);
|
||||||
if (frame->no == frameNo) {
|
if (mathEqual(frame->no, frameNo)) return fill->colorStops(frame->value.data, count);
|
||||||
return fill->colorStops(frame->value.data, count);
|
|
||||||
}
|
|
||||||
|
|
||||||
//interpolate
|
//interpolate
|
||||||
auto t = (frameNo - frame->no) / ((frame + 1)->no - frame->no);
|
auto t = (frameNo - frame->no) / ((frame + 1)->no - frame->no);
|
||||||
|
@ -719,7 +715,7 @@ struct LottiePosition : LottieProperty
|
||||||
if (frameNo >= frames->last().no) return frames->last().value;
|
if (frameNo >= frames->last().no) return frames->last().value;
|
||||||
|
|
||||||
auto frame = frames->data + _bsearch(frames, frameNo);
|
auto frame = frames->data + _bsearch(frames, frameNo);
|
||||||
if (frame->no == frameNo) return frame->value;
|
if (mathEqual(frame->no, frameNo)) return frame->value;
|
||||||
return frame->interpolate(frame + 1, frameNo);
|
return frame->interpolate(frame + 1, frameNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue