From 979237515ce2921b9552a99eda071e9e9a14297a Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 17 Sep 2019 15:52:58 +1000 Subject: [PATCH] [properties] Do not return nan values when an assistant is used with min val == max val Fixes #31242 --- src/core/qgspropertytransformer.cpp | 3 +++ tests/src/core/testqgsproperty.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/src/core/qgspropertytransformer.cpp b/src/core/qgspropertytransformer.cpp index a975035e356..0e5dc92c67e 100644 --- a/src/core/qgspropertytransformer.cpp +++ b/src/core/qgspropertytransformer.cpp @@ -175,6 +175,9 @@ bool QgsGenericNumericTransformer::loadVariant( const QVariant &transformer ) double QgsGenericNumericTransformer::value( double input ) const { + if ( qgsDoubleNear( mMaxValue, mMinValue ) ) + return qBound( mMinOutput, input, mMaxOutput ); + input = transformNumeric( input ); if ( qgsDoubleNear( mExponent, 1.0 ) ) return mMinOutput + ( qBound( mMinValue, input, mMaxValue ) - mMinValue ) * ( mMaxOutput - mMinOutput ) / ( mMaxValue - mMinValue ); diff --git a/tests/src/core/testqgsproperty.cpp b/tests/src/core/testqgsproperty.cpp index a4ad077e294..ac0a5de01e2 100644 --- a/tests/src/core/testqgsproperty.cpp +++ b/tests/src/core/testqgsproperty.cpp @@ -807,6 +807,13 @@ void TestQgsProperty::genericNumericTransformer() QGSCOMPARENEAR( t.value( 150 ), 13.5355, 0.001 ); QCOMPARE( t.value( 200 ), 20.0 ); + // invalid settings, where minValue = maxValue + QgsGenericNumericTransformer invalid( 1.0, 1.0, 0, 1.0 ); + QCOMPARE( invalid.value( -1 ), 0.0 ); + QCOMPARE( invalid.value( 0 ), 0.0 ); + QCOMPARE( invalid.value( 1.0 ), 1.0 ); + QCOMPARE( invalid.value( 2.0 ), 1.0 ); + //as expression QgsGenericNumericTransformer t3( 15, 25,