Skip to content

Commit

Permalink
Merge pull request #39859 from root676/fix_random_raster
Browse files Browse the repository at this point in the history
Fix random raster Float32/64 support
  • Loading branch information
nyalldawson committed Nov 6, 2020
2 parents 608d717 + 2e5276d commit 0b5c734
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/analysis/processing/qgsalgorithmrandomraster.cpp
Expand Up @@ -272,9 +272,6 @@ bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters( const QVariantMap
mRandomUpperBound = parameterAsDouble( parameters, QStringLiteral( "UPPER_BOUND" ), context );
mRandomLowerBound = parameterAsDouble( parameters, QStringLiteral( "LOWER_BOUND" ), context );

mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );

if ( mRandomLowerBound > mRandomUpperBound )
throw QgsProcessingException( QObject::tr( "The chosen lower bound for random number range is greater than the upper bound. The lower bound value must be smaller than the upper bound value." ) );

Expand Down Expand Up @@ -346,6 +343,10 @@ bool QgsRandomUniformRasterAlgorithm::prepareRandomParameters( const QVariantMap
default:
break;
}

mRandomUniformIntDistribution = std::uniform_int_distribution<long>( mRandomLowerBound, mRandomUpperBound );
mRandomUniformDoubleDistribution = std::uniform_real_distribution<double>( mRandomLowerBound, mRandomUpperBound );

return true;
}

Expand All @@ -356,7 +357,7 @@ long QgsRandomUniformRasterAlgorithm::generateRandomLongValue( std::mt19937 &mer

double QgsRandomUniformRasterAlgorithm::generateRandomDoubleValue( std::mt19937 &mersenneTwister )
{
return mRandomUniformIntDistribution( mersenneTwister );
return mRandomUniformDoubleDistribution( mersenneTwister );
}

//
Expand Down

0 comments on commit 0b5c734

Please sign in to comment.