@@ -192,6 +192,7 @@ bool QgsGenericNumericTransformer::readXml( const QDomElement &transformerElem,
192
192
193
193
double QgsGenericNumericTransformer::value ( double input ) const
194
194
{
195
+ input = transformNumeric ( input );
195
196
if ( qgsDoubleNear ( mExponent , 1.0 ) )
196
197
return mMinOutput + ( qBound ( mMinValue , input, mMaxValue ) - mMinValue ) * ( mMaxOutput - mMinOutput ) / ( mMaxValue - mMinValue );
197
198
else
@@ -211,7 +212,7 @@ QVariant QgsGenericNumericTransformer::transform( const QgsExpressionContext& co
211
212
if ( ok )
212
213
{
213
214
// apply scaling to value
214
- return value ( transformNumeric ( dblValue ) );
215
+ return value ( dblValue );
215
216
}
216
217
else
217
218
{
@@ -386,6 +387,8 @@ bool QgsSizeScaleTransformer::readXml( const QDomElement &transformerElem, const
386
387
387
388
double QgsSizeScaleTransformer::size ( double value ) const
388
389
{
390
+ value = transformNumeric ( value );
391
+
389
392
switch ( mType )
390
393
{
391
394
case Linear:
@@ -433,7 +436,7 @@ QVariant QgsSizeScaleTransformer::transform( const QgsExpressionContext& context
433
436
if ( ok )
434
437
{
435
438
// apply scaling to value
436
- return size ( transformNumeric ( dblValue ) );
439
+ return size ( dblValue );
437
440
}
438
441
else
439
442
{
@@ -638,7 +641,7 @@ QVariant QgsColorRampTransformer::transform( const QgsExpressionContext &context
638
641
if ( ok )
639
642
{
640
643
// apply scaling to value
641
- return color ( transformNumeric ( dblValue ) );
644
+ return color ( dblValue );
642
645
}
643
646
else
644
647
{
@@ -661,6 +664,7 @@ QString QgsColorRampTransformer::toExpression( const QString& baseExpression ) c
661
664
662
665
QColor QgsColorRampTransformer::color ( double value ) const
663
666
{
667
+ value = transformNumeric ( value );
664
668
double scaledVal = qBound ( 0.0 , ( value - mMinValue ) / ( mMaxValue - mMinValue ), 1.0 );
665
669
666
670
if ( !mGradientRamp )
@@ -733,6 +737,11 @@ void QgsCurveTransform::setControlPoints( const QList<QgsPoint>& points )
733
737
{
734
738
mControlPoints = points;
735
739
std::sort ( mControlPoints .begin (), mControlPoints .end (), sortByX );
740
+ for ( int i = 0 ; i < mControlPoints .count (); ++i )
741
+ {
742
+ mControlPoints [ i ] = QgsPoint ( qBound ( 0.0 , mControlPoints .at ( i ).x (), 1.0 ),
743
+ qBound ( 0.0 , mControlPoints .at ( i ).y (), 1.0 ) );
744
+ }
736
745
calcSecondDerivativeArray ();
737
746
}
738
747
@@ -769,27 +778,27 @@ double QgsCurveTransform::y( double x ) const
769
778
{
770
779
int n = mControlPoints .count ();
771
780
if ( n < 2 )
772
- return x ; // invalid
781
+ return qBound ( 0.0 , x, 1.0 ) ; // invalid
773
782
else if ( n < 3 )
774
783
{
775
784
// linear
776
785
if ( x <= mControlPoints .at ( 0 ).x () )
777
- return mControlPoints .at ( 0 ).y ();
786
+ return qBound ( 0.0 , mControlPoints .at ( 0 ).y (), 1.0 );
778
787
else if ( x >= mControlPoints .at ( n - 1 ).x () )
779
- return mControlPoints .at ( 1 ).y ();
788
+ return qBound ( 0.0 , mControlPoints .at ( 1 ).y (), 1.0 );
780
789
else
781
790
{
782
791
double dx = mControlPoints .at ( 1 ).x () - mControlPoints .at ( 0 ).x ();
783
792
double dy = mControlPoints .at ( 1 ).y () - mControlPoints .at ( 0 ).y ();
784
- return x * ( dy / dx ) + mControlPoints .at ( 0 ).y ();
793
+ return qBound ( 0.0 , ( x - mControlPoints . at ( 0 ). x () ) * ( dy / dx ) + mControlPoints .at ( 0 ).y (), 1.0 );
785
794
}
786
795
}
787
796
788
797
// safety check
789
798
if ( x <= mControlPoints .at ( 0 ).x () )
790
- return mControlPoints .at ( 0 ).y ();
799
+ return qBound ( 0.0 , mControlPoints .at ( 0 ).y (), 1.0 );
791
800
if ( x >= mControlPoints .at ( n - 1 ).x () )
792
- return mControlPoints .at ( n - 1 ).y ();
801
+ return qBound ( 0.0 , mControlPoints .at ( n - 1 ).y (), 1.0 );
793
802
794
803
// find corresponding segment
795
804
QList<QgsPoint>::const_iterator pointIt = mControlPoints .constBegin ();
@@ -807,7 +816,8 @@ double QgsCurveTransform::y( double x ) const
807
816
808
817
double a = 1 - t;
809
818
810
- return a*currentControlPoint.y () + t*nextControlPoint.y () + ( h*h / 6 )*(( a*a*a - a )*mSecondDerivativeArray [i] + ( t*t*t - t )*mSecondDerivativeArray [i+1 ] );
819
+ return qBound ( 0.0 , a*currentControlPoint.y () + t*nextControlPoint.y () + ( h*h / 6 )*(( a*a*a - a )*mSecondDerivativeArray [i] + ( t*t*t - t )*mSecondDerivativeArray [i+1 ] ),
820
+ 1.0 );
811
821
}
812
822
813
823
++pointIt;
@@ -819,7 +829,7 @@ double QgsCurveTransform::y( double x ) const
819
829
}
820
830
821
831
// should not happen
822
- return x ;
832
+ return qBound ( 0.0 , x, 1.0 ) ;
823
833
}
824
834
825
835
// this code is adapted from https://github.com/OpenFibers/Photoshop-Curves
@@ -851,7 +861,7 @@ QVector<double> QgsCurveTransform::y( const QVector<double>& x ) const
851
861
// safety check
852
862
while ( currentX <= currentControlPoint.x () )
853
863
{
854
- result << currentControlPoint.y ();
864
+ result << qBound ( 0.0 , currentControlPoint.y (), 1.0 );
855
865
xIndex++;
856
866
currentX = x.at ( xIndex );
857
867
}
@@ -867,7 +877,7 @@ QVector<double> QgsCurveTransform::y( const QVector<double>& x ) const
867
877
868
878
double a = 1 - t;
869
879
870
- result << a*currentControlPoint.y () + t*nextControlPoint.y () + ( h*h / 6 )*(( a*a*a - a )*mSecondDerivativeArray [i] + ( t*t*t - t )*mSecondDerivativeArray [i+1 ] );
880
+ result << qBound ( 0.0 , a*currentControlPoint.y () + t*nextControlPoint.y () + ( h*h / 6 )*(( a*a*a - a )*mSecondDerivativeArray [i] + ( t*t*t - t )*mSecondDerivativeArray [i+1 ] ), 1.0 );
871
881
xIndex++;
872
882
if ( xIndex == x.count () )
873
883
return result;
@@ -886,7 +896,7 @@ QVector<double> QgsCurveTransform::y( const QVector<double>& x ) const
886
896
// safety check
887
897
while ( xIndex < x.count () )
888
898
{
889
- result << nextControlPoint.y ();
899
+ result << qBound ( 0.0 , nextControlPoint.y (), 1.0 );
890
900
xIndex++;
891
901
}
892
902
0 commit comments