From 432ca6166976bd093d1c3921aa72d9b72865eeeb Mon Sep 17 00:00:00 2001 From: Laurent Balland-Poirier Date: Wed, 30 Sep 2015 16:57:41 +0200 Subject: 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 Tested-by: Noel Grandin --- chart2/source/tools/PolynomialRegressionCurveCalculator.cxx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'chart2') 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) { -- cgit