C++ (Qt)struct CFrameRange { int mStart = 0; // первый кадр int mSttop = 12; // последний кадр int mCount = 4; // число вариантов выбора};
C++ (Qt)int CFrameRange::Val2Frame( float val ) const{ ???}
int CFrameRange::Val2Frame( float val ) const{ int index = atoi(std::to_string(val).replace("0.", "")); return index;}
C++ (Qt)int len = stop - start;int result = (len * val) / count;result *= count;
int CFrameRange::Val2Frame( float val ) const{ int len = stop - start; int lenInterval = len / count; float intervalPercent = (float)1 / lenInterval; int intervalIndex = floor(val / intervalPercent); float minFramePercent = intervalIndex * intervalPercent; float maxFramePercent = (intervalIndex + 1) * intervalPercent; float minFrameDiff = abs(minFramePercent - val); float maxFrameDiff = abs(maxFramePercent - val); int step = len / lenInterval; float framePer; if (minFrameDiff < maxFrameDiff) { framePer = minFramePercent; }else { framePer = maxFramePercent; } return step * (framePer / intervalPercent);}
C++ (Qt)int CFrameRange::Val2Frame( float val ) const{ int index = int(val * mCount); float step = float(mStop - mStart) / (mCount - 1); int frame = int(index * step + 0.5f) + mStart; return qBound(mStart, frame, mStop);}