From 240ced94e48d91a55b755730e54d97c7e7521fd0 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Tue, 24 Dec 2024 11:02:29 +0100 Subject: [PATCH 1/3] Fix examples of the scale_exponential expression function --- resources/function_help/json/scale_exponential | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/function_help/json/scale_exponential b/resources/function_help/json/scale_exponential index b201e3d4f223..44968e926f3e 100644 --- a/resources/function_help/json/scale_exponential +++ b/resources/function_help/json/scale_exponential @@ -23,12 +23,12 @@ "description": "A positive value (greater than 0), which dictates the way input values are mapped to the output range. Large exponents will cause the output values to 'ease in', starting slowly before accelerating as the input values approach the domain maximum. Smaller exponents (less than 1) will cause output values to 'ease out', where the mapping starts quickly but slows as it approaches the domain maximum." }], "examples": [{ - "expression": "scale_exp(5,0,10,0,100,2)", - "returns": "25", + "expression": "scale_exponential(5,0,10,0,100,2)", + "returns": "3.030", "note": "easing in, using an exponent of 2" }, { - "expression": "scale_exp(3,0,10,0,100,0.5)", - "returns": "54.772", + "expression": "scale_exponential(3,0,10,0,100,0.5)", + "returns": "87.585", "note": "easing out, using an exponent of 0.5" }], "tags": ["exponential", "curve", "ease", "transforms", "output", "given", "input", "domain", "range", "specified", "values"] From d0a10dab33152890bf5b7ca8759330faea0b2979 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Wed, 25 Dec 2024 21:40:08 +0100 Subject: [PATCH 2/3] Add function examples to tests --- tests/src/core/testqgsexpression.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index c9bea99a30fc..38baf09aca28 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -993,6 +993,8 @@ class TestQgsExpression : public QObject QTest::newRow( "scale_linear(10,0,10,100,200)" ) << "scale_linear(10,0,10,100,200)" << false << QVariant( 200. ); QTest::newRow( "scale_linear(-1,0,10,100,200)" ) << "scale_linear(-1,0,10,100,200)" << false << QVariant( 100. ); QTest::newRow( "scale_linear(11,0,10,100,200)" ) << "scale_linear(11,0,10,100,200)" << false << QVariant( 200. ); + QTest::newRow( "scale_linear(5,0,10,0,100,2)" ) << "scale_linear(5,0,10,0,100,2)" << false << QVariant( 50. ); + QTest::newRow( "scale_linear(1500,1000,10000,9,20)" ) << "scale_linear(1500,1000,10000,9,20)" << false << QVariant( 9.61111111111111 ); // previously had name scale_exp, but renamed to scale_polynomial as it uses polynomial interpolation formula // see https://github.com/qgis/QGIS/pull/53164 for more details @@ -1002,6 +1004,8 @@ class TestQgsExpression : public QObject QTest::newRow( "scale_polynomial(10,0,10,100,200,0.5)" ) << "scale_polynomial(10,0,10,100,200,0.5)" << false << QVariant( 200. ); QTest::newRow( "scale_polynomial(-1,0,10,100,200,0.5)" ) << "scale_polynomial(-1,0,10,100,200,0.5)" << false << QVariant( 100. ); QTest::newRow( "scale_polynomial(4,0,9,0,90,0.5)" ) << "scale_polynomial(4,0,9,0,90,0.5)" << false << QVariant( 60. ); + QTest::newRow( "scale_polynomial(5,0,10,0,100,2)" ) << "scale_polynomial(5,0,10,0,100,2)" << false << QVariant( 25. ); + QTest::newRow( "scale_polynomial(3,0,10,0,100,0.5)" ) << "scale_polynomial(3,0,10,0,100,0.5)" << false << QVariant( 54.77225575051661 ); // this is an alias for scale_polynomial to preserve backward compatibility QTest::newRow( "scale_exp(0.5,0,1,0,1,2)" ) << "scale_exp(0.5,0,1,0,1,2)" << false << QVariant( 0.25 ); QTest::newRow( "scale_exp(0,0,10,100,200,2)" ) << "scale_exp(0,0,10,100,200,2)" << false << QVariant( 100. ); @@ -1016,6 +1020,8 @@ class TestQgsExpression : public QObject QTest::newRow( "scale_exponential(10,0,10,100,200,0.5)" ) << "scale_exponential(10,0,10,100,200,0.5)" << false << QVariant( 200. ); QTest::newRow( "scale_exponential(-1,0,10,100,200,0.5)" ) << "scale_exponential(-1,0,10,100,200,0.5)" << false << QVariant( 100. ); QTest::newRow( "scale_exponential(4,0,9,0,90,0.5)" ) << "scale_exponential(4,0,9,0,90,0.5)" << false << QVariant( 84.5401174168 ); + QTest::newRow( "scale_exponential(5,0,10,0,100,2)" ) << "scale_exponential(5,0,10,0,100,2)" << false << QVariant( 3.0303030303030303 ); + QTest::newRow( "scale_exponential(3,0,10,0,100,0.5)" ) << "scale_exponential(3,0,10,0,100,0.5)" << false << QVariant( 87.58553274682306 ); // cast functions QTest::newRow( "double to int" ) << "toint(3.2)" << false << QVariant( 3 ); From 01a2143b9c115de9813bf40d874324c84b67d840 Mon Sep 17 00:00:00 2001 From: Harrissou Sant-anna Date: Thu, 26 Dec 2024 03:07:30 +0100 Subject: [PATCH 3/3] Fix and complete tests Co-authored-by: Andrea Giudiceandrea --- tests/src/core/testqgsexpression.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index 38baf09aca28..23aafcdffe92 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -993,7 +993,8 @@ class TestQgsExpression : public QObject QTest::newRow( "scale_linear(10,0,10,100,200)" ) << "scale_linear(10,0,10,100,200)" << false << QVariant( 200. ); QTest::newRow( "scale_linear(-1,0,10,100,200)" ) << "scale_linear(-1,0,10,100,200)" << false << QVariant( 100. ); QTest::newRow( "scale_linear(11,0,10,100,200)" ) << "scale_linear(11,0,10,100,200)" << false << QVariant( 200. ); - QTest::newRow( "scale_linear(5,0,10,0,100,2)" ) << "scale_linear(5,0,10,0,100,2)" << false << QVariant( 50. ); + QTest::newRow( "scale_linear(5,0,10,0,100)" ) << "scale_linear(5,0,10,0,100)" << false << QVariant( 50. ); + QTest::newRow( "scale_linear(0.2,0,1,0,360)" ) << "scale_linear(0.2,0,1,0,360)" << false << QVariant( 72. ); QTest::newRow( "scale_linear(1500,1000,10000,9,20)" ) << "scale_linear(1500,1000,10000,9,20)" << false << QVariant( 9.61111111111111 ); // previously had name scale_exp, but renamed to scale_polynomial as it uses polynomial interpolation formula