From kde-commits Fri Oct 31 20:08:20 2003 From: Mark Kretschmann Date: Fri, 31 Oct 2003 20:08:20 +0000 To: kde-commits Subject: kdenonbeta/amarok/amarok X-MARC-Message: https://marc.info/?l=kde-commits&m=106764421132430 CVS commit by markey: fix analyzer interpolation M +13 -5 viswidget.cpp 1.9 --- kdenonbeta/amarok/amarok/viswidget.cpp #1.8:1.9 @@ -176,15 +176,23 @@ std::vector* VisWidget::interpola double pos = 0.0; - double step = (double) oldVec->size() / newSize; + double step = static_cast( oldVec->size() ) / newSize; for ( int i = 0; i < newSize; i++ ) { double error = pos - floor( pos ); - unsigned long offset = (unsigned long) pos; + unsigned long offset = static_cast( pos ); - if ( offset >= oldVec->size() - 2 ) - offset = oldVec->size() - 2; + unsigned long indexLeft = offset + 0; - newVec->at( i ) = oldVec->at( offset + 0 ) * ( 1.0 - error ) + oldVec->at( offset + 1 ) * error; + if ( indexLeft > oldVec->size() - 1 ) + indexLeft = oldVec->size() - 1; + + unsigned long indexRight = offset + 1; + + if ( indexRight > oldVec->size() - 1 ) + indexRight = oldVec->size() - 1; + + newVec->at( i ) = oldVec->at( indexLeft ) * ( 1.0 - error ) + + oldVec->at( indexRight ) * error; pos += step; }