mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
animation/lottie: improved the precision of frame values.
Refined the logic for updating frame numbers to ensure greater accuracy in value precision. issue: https://github.com/thorvg/thorvg/issues/2266
This commit is contained in:
parent
6a9a390e9d
commit
38bd34b01f
3 changed files with 11 additions and 7 deletions
|
@ -1805,6 +1805,7 @@ public:
|
||||||
*
|
*
|
||||||
* @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
|
* @note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
|
||||||
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
|
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
|
||||||
|
* Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
|
||||||
*
|
*
|
||||||
* @see totalFrame()
|
* @see totalFrame()
|
||||||
*
|
*
|
||||||
|
|
|
@ -2254,6 +2254,7 @@ TVG_API Tvg_Animation* tvg_animation_new();
|
||||||
*
|
*
|
||||||
* \note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
|
* \note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value
|
||||||
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
|
* is less than 0.001. In such cases, it returns @c Result::InsufficientCondition.
|
||||||
|
* Values less than 0.001 may be disregarded and may not be accurately retained by the Animation.
|
||||||
* \see tvg_animation_get_total_frame()
|
* \see tvg_animation_get_total_frame()
|
||||||
*
|
*
|
||||||
* \since 0.13
|
* \since 0.13
|
||||||
|
|
|
@ -313,17 +313,19 @@ bool LottieLoader::override(const char* slot)
|
||||||
|
|
||||||
bool LottieLoader::frame(float no)
|
bool LottieLoader::frame(float no)
|
||||||
{
|
{
|
||||||
|
auto frameNo = no + startFrame();
|
||||||
|
|
||||||
|
//This ensures that the target frame number is reached.
|
||||||
|
frameNo *= 10000.0f;
|
||||||
|
frameNo = roundf(frameNo);
|
||||||
|
frameNo *= 0.0001f;
|
||||||
|
|
||||||
//Skip update if frame diff is too small.
|
//Skip update if frame diff is too small.
|
||||||
if (fabsf(this->frameNo - no) < 0.0009f) return false;
|
if (fabsf(this->frameNo - frameNo) <= 0.0009f) return false;
|
||||||
|
|
||||||
this->done();
|
this->done();
|
||||||
|
|
||||||
//This ensures that the perfect last frame is reached.
|
this->frameNo = frameNo;
|
||||||
no *= 1000.0f;
|
|
||||||
no = roundf(no);
|
|
||||||
no *= 0.001f;
|
|
||||||
|
|
||||||
this->frameNo = no + startFrame();
|
|
||||||
|
|
||||||
TaskScheduler::request(this);
|
TaskScheduler::request(this);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue