diff options
author | Laurent Balland-Poirier <laurent.balland-poirier@laposte.net> | 2015-09-30 16:57:41 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-10-07 10:47:57 +0000 |
commit | 432ca6166976bd093d1c3921aa72d9b72865eeeb (patch) | |
tree | d328637e0776c5424b5954e3451a390c55782eea /chart2 | |
parent | bb76b8f10697f3d5ca1f9a2f19902b043bd61cd7 (diff) |
Improve polynomial trend line equation
Skip coefficient if its value is 1 (or near 1)
Change-Id: I39a5630cc76250ded1ab22709522344d42fcc0e9
Reviewed-on: https://gerrit.libreoffice.org/19037
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx index 176e98b57f0b..1d26611c865a 100644 --- a/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx +++ b/chart2/source/tools/PolynomialRegressionCurveCalculator.cxx @@ -238,6 +238,7 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( OUStringBuffer aBuf( "f(x) = "); sal_Int32 aLastIndex = mCoefficients.size() - 1; + bool bFindValue = false; for (sal_Int32 i = aLastIndex; i >= 0; i--) { double aValue = mCoefficients[i]; @@ -248,14 +249,17 @@ OUString PolynomialRegressionCurveCalculator::ImplGetRepresentation( else if (aValue < 0.0) { aBuf.append( " - " ); + aValue = - aValue; } else { - if (i != aLastIndex) + if ( bFindValue ) aBuf.append( " + " ); } + bFindValue = true; - aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, std::abs( aValue ) ) ); + if ( i == 0 || !rtl::math::approxEqual( aValue , 1.0 ) ) + aBuf.append( getFormattedString( xNumFormatter, nNumberFormatKey, aValue ) ); if(i > 0) { |