Fixed BorderWidthImpl::GuessWidth()

This commit is contained in:
Cédric Bosdonnat 2010-12-24 09:58:37 +01:00
parent b717148057
commit bffee3e11a

View file

@ -818,33 +818,65 @@ long BorderWidthImpl::GetGap( long nWidth ) const
return result;
}
long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
{
long nWidth = 0;
if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
nWidth = double( nLine1 ) / m_nRate1;
if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
double nWidth = 0.0;
if ( nChanging )
nWidth = double( nTested ) / nRate;
else
{
double nLine2Width = double( nLine2 ) / m_nRate2;
if ( nWidth > 0 && nWidth != nLine2Width )
nWidth = 0;
if ( double( nTested ) == nRate )
nWidth = nRate;
else
nWidth = nLine2Width;
}
if ( ( m_nFlags & CHANGE_DIST ) > 0 )
{
double nDistWidth = double( nGap ) / m_nRateGap;
if ( nWidth > 0 && nWidth != nDistWidth )
nWidth = 0;
else
nWidth = nDistWidth;
nWidth = 0.0;
}
return nWidth;
}
long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
{
std::vector< double > aToCompare;
bool bInvalid = false;
bool bLine1Change = ( m_nFlags & CHANGE_LINE1 ) > 0;
double nWidth1 = lcl_getGuessedWidth( nLine1, m_nRate1, bLine1Change );
if ( bLine1Change )
aToCompare.push_back( nWidth1 );
else if ( !bLine1Change && nWidth1 == 0 )
bInvalid = true;
bool bLine2Change = ( m_nFlags & CHANGE_LINE2 ) > 0;
double nWidth2 = lcl_getGuessedWidth( nLine2, m_nRate2, bLine2Change );
if ( bLine2Change )
aToCompare.push_back( nWidth2 );
else if ( !bLine2Change && nWidth2 == 0 )
bInvalid = true;
bool bGapChange = ( m_nFlags & CHANGE_DIST ) > 0;
double nWidthGap = lcl_getGuessedWidth( nGap, m_nRateGap, bGapChange );
if ( bGapChange )
aToCompare.push_back( nWidthGap );
else if ( !bGapChange && nWidthGap == 0 )
bInvalid = true;
double nWidth = 0.0;
if ( !bInvalid && aToCompare.size() > 0 )
{
nWidth = *aToCompare.begin();
std::vector< double >::iterator pIt = aToCompare.begin();
while ( pIt != aToCompare.end() && !bInvalid )
{
bInvalid = ( nWidth != *pIt );
pIt++;
}
if ( bInvalid )
nWidth = 0.0;
}
return long( nWidth );
}
class ImpLineStyleListData
{
private: