Skip to content
Permalink
Browse files

[qt6] Switch from qrand to std::rand

  • Loading branch information
m-kuhn committed Mar 25, 2021
1 parent cd17a85 commit b024eea2615325146b9aaca130e39d880c81ae43
Showing with 9 additions and 9 deletions.
  1. +9 −9 src/core/qgscolorramp.cpp
@@ -401,7 +401,7 @@ QList<QColor> QgsLimitedRandomColorRamp::randomColors( int count,
int safeValMin = std::min( valMin, valMax );

//start hue at random angle
double currentHueAngle = 360.0 * static_cast< double >( qrand() ) / RAND_MAX;
double currentHueAngle = 360.0 * static_cast< double >( std::rand() ) / RAND_MAX;

colors.reserve( count );
for ( int i = 0; i < count; ++i )
@@ -412,8 +412,8 @@ QList<QColor> QgsLimitedRandomColorRamp::randomColors( int count,
currentHueAngle += 137.50776;
//scale hue to between hueMax and hueMin
h = std::clamp( std::round( ( std::fmod( currentHueAngle, 360.0 ) / 360.0 ) * ( safeHueMax - safeHueMin ) + safeHueMin ), 0.0, 359.0 );
s = std::clamp( ( qrand() % ( safeSatMax - safeSatMin + 1 ) ) + safeSatMin, 0, 255 );
v = std::clamp( ( qrand() % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 0, 255 );
s = std::clamp( ( static_cast<int>( std::rand() ) % ( safeSatMax - safeSatMin + 1 ) ) + safeSatMin, 0, 255 );
v = std::clamp( ( static_cast<int>( std::rand() ) % ( safeValMax - safeValMin + 1 ) ) + safeValMin, 0, 255 );
colors.append( QColor::fromHsv( h, s, v ) );
}
return colors;
@@ -451,9 +451,9 @@ QColor QgsRandomColorRamp::color( double value ) const
}

//can't use precalculated hues, use a totally random hue
int h = static_cast< int >( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
int s = ( qrand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
int v = ( qrand() % ( maxVal - minVal + 1 ) ) + minVal;
int h = static_cast< int >( 360.0 * std::rand() / ( RAND_MAX + 1.0 ) );
int s = ( std::rand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
int v = ( std::rand() % ( maxVal - minVal + 1 ) ) + minVal;
return QColor::fromHsv( h, s, v );
}

@@ -467,7 +467,7 @@ void QgsRandomColorRamp::setTotalColorCount( const int colorCount )
//similar colors being picked. TODO - investigate alternative "n-visually distinct color" routines

//random offsets
double hueOffset = ( 360.0 * qrand() / ( RAND_MAX + 1.0 ) );
double hueOffset = ( 360.0 * std::rand() / ( RAND_MAX + 1.0 ) );

//try to maximise difference between hues. this is not an ideal implementation, as constant steps
//through the hue wheel are not visually perceived as constant changes in hue
@@ -479,8 +479,8 @@ void QgsRandomColorRamp::setTotalColorCount( const int colorCount )
for ( int idx = 0; idx < colorCount; ++ idx )
{
int h = static_cast< int >( std::round( currentHue ) ) % 360;
int s = ( qrand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
int v = ( qrand() % ( DEFAULT_RANDOM_VAL_MAX - DEFAULT_RANDOM_VAL_MIN + 1 ) ) + DEFAULT_RANDOM_VAL_MIN;
int s = ( std::rand() % ( DEFAULT_RANDOM_SAT_MAX - DEFAULT_RANDOM_SAT_MIN + 1 ) ) + DEFAULT_RANDOM_SAT_MIN;
int v = ( std::rand() % ( DEFAULT_RANDOM_VAL_MAX - DEFAULT_RANDOM_VAL_MIN + 1 ) ) + DEFAULT_RANDOM_VAL_MIN;
mPrecalculatedColors << QColor::fromHsv( h, s, v );
currentHue += hueStep;
}

0 comments on commit b024eea

Please sign in to comment.