mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 20:14:37 +00:00
lottie: ++binary search stability.
this ensures that the return value is not below 0, when the frame count is just 2.
This commit is contained in:
parent
9e6a837125
commit
5a8e15aebd
1 changed files with 5 additions and 4 deletions
|
@ -195,17 +195,18 @@ struct LottieVectorFrame
|
|||
template<typename T>
|
||||
uint32_t bsearch(T* frames, float frameNo)
|
||||
{
|
||||
uint32_t low = 0;
|
||||
uint32_t high = frames->count - 1;
|
||||
int32_t low = 0;
|
||||
int32_t high = int32_t(frames->count) - 1;
|
||||
|
||||
while (low <= high) {
|
||||
auto mid = low + (high - low) / 2;
|
||||
auto frame = frames->data + mid;
|
||||
if (mathEqual(frameNo, frame->no)) return mid;
|
||||
else if (frameNo < frame->no) high = mid - 1;
|
||||
if (frameNo < frame->no) high = mid - 1;
|
||||
else low = mid + 1;
|
||||
}
|
||||
if (high < low) low = high;
|
||||
if (low < 0) low = 0;
|
||||
|
||||
return low;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue