basegfx/source/tools/gradienttools.cxx                 |    9 +++++----
 drawinglayer/source/processor2d/vclprocessor2d.cxx     |    4 ++--
 stoc/test/testiadapter.cxx                             |    3 ++-
 stoc/test/testintrosp.cxx                              |    3 ++-
 sw/source/core/bastyp/calc.cxx                         |    2 +-
 testtools/source/bridgetest/bridgetest.cxx             |   10 ++++++----
 testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx |    9 +++++----
 vcl/source/gdi/gradient.cxx                            |    5 +++--
 8 files changed, 26 insertions(+), 19 deletions(-)

New commits:
commit 49746f40b06eaf1f61bb54454408a06a49d73c5e
Author:     Kunal Pawar <hellokunalpa...@gmail.com>
AuthorDate: Thu Feb 10 13:20:06 2022 +0530
Commit:     Hossein <hoss...@libreoffice.org>
CommitDate: Tue Feb 15 21:00:18 2022 +0100

    tdf#145759 Use symbolic constants instead of magic numerical constants
    
    1.4142... -> M_SQRT2
    0.4142... -> M_SQRT2 - 1
    3.1415... -> M_PI
    2.7182... -> M_E
    
    Change-Id: If5b19aa38d9902b1a4b717f89f18bdf2f73a47cf
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129745
    Tested-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Hossein <hoss...@libreoffice.org>

diff --git a/basegfx/source/tools/gradienttools.cxx 
b/basegfx/source/tools/gradienttools.cxx
index 3605d8fe0be0..b4f1f6222f52 100644
--- a/basegfx/source/tools/gradienttools.cxx
+++ b/basegfx/source/tools/gradienttools.cxx
@@ -21,6 +21,7 @@
 #include <basegfx/point/b2dpoint.hxx>
 #include <basegfx/range/b2drange.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
+#include <cmath>
 
 namespace basegfx
 {
@@ -144,10 +145,10 @@ namespace basegfx
         }
         else
         {
-            fTargetOffsetX -= (0.4142 / 2.0 ) * fTargetSizeX;
-            fTargetOffsetY -= (0.4142 / 2.0 ) * fTargetSizeY;
-            fTargetSizeX = 1.4142 * fTargetSizeX;
-            fTargetSizeY = 1.4142 * fTargetSizeY;
+            fTargetOffsetX -= ((M_SQRT2 - 1) / 2.0 ) * fTargetSizeX;
+            fTargetOffsetY -= ((M_SQRT2 - 1) / 2.0 ) * fTargetSizeY;
+            fTargetSizeX = M_SQRT2 * fTargetSizeX;
+            fTargetSizeY = M_SQRT2 * fTargetSizeY;
         }
 
         const double fHalfBorder((1.0 - fBorder) * 0.5);
diff --git a/drawinglayer/source/processor2d/vclprocessor2d.cxx 
b/drawinglayer/source/processor2d/vclprocessor2d.cxx
index 04258b288277..da34cd558a81 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.cxx
@@ -1291,7 +1291,7 @@ void VclProcessor2D::RenderSvgLinearAtomPrimitive2D(
     const basegfx::B2DVector aDiscreteVector(
         getViewInformation2D().getInverseObjectToViewTransformation()
         * basegfx::B2DVector(1.0, 1.0));
-    const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 
1.414213562373));
+    const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / M_SQRT2));
 
     // use color distance and discrete lengths to calculate step count
     const sal_uInt32 nSteps(calculateStepsForSvgGradient(aColorA, aColorB, 
fDelta, fDiscreteUnit));
@@ -1335,7 +1335,7 @@ void VclProcessor2D::RenderSvgRadialAtomPrimitive2D(
     const basegfx::B2DVector aDiscreteVector(
         getViewInformation2D().getInverseObjectToViewTransformation()
         * basegfx::B2DVector(1.0, 1.0));
-    const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / 
1.414213562373));
+    const double fDiscreteUnit(aDiscreteVector.getLength() * (1.0 / M_SQRT2));
 
     // use color distance and discrete lengths to calculate step count
     const sal_uInt32 nSteps(
diff --git a/stoc/test/testiadapter.cxx b/stoc/test/testiadapter.cxx
index 1525032d2af3..d9fd9560c13a 100644
--- a/stoc/test/testiadapter.cxx
+++ b/stoc/test/testiadapter.cxx
@@ -37,6 +37,7 @@
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 
 #include <cppuhelper/implbase.hxx>
+#include <cmath>
 
 
 using namespace test;
@@ -749,7 +750,7 @@ sal_Bool performTest( const Reference<XLanguageBindingTest 
> & xLBT )
                 sal_True, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
                 SAL_CONST_INT64(0x123456789abcdef0),
                 SAL_CONST_UINT64(0xfedcba9876543210),
-                (float)17.0815, 3.1415926359, TestEnum_LOLA, 
OUString("dumdidum"), xI,
+                (float)17.0815, M_PI, TestEnum_LOLA, OUString("dumdidum"), xI,
                 Any( &xI, cppu::UnoType<XInterface>::get()) );
 
         OSL_ENSURE( aData.Any == xI, "### unexpected any!" );
diff --git a/stoc/test/testintrosp.cxx b/stoc/test/testintrosp.cxx
index e33ee178e3e9..0b56c8564ef9 100644
--- a/stoc/test/testintrosp.cxx
+++ b/stoc/test/testintrosp.cxx
@@ -40,6 +40,7 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <cmath>
 
 using namespace cppu;
 using namespace ModuleA;
@@ -454,7 +455,7 @@ void ImplIntroTest::Init()
 
     //XInterfaceRef Source;
     Any Value;
-    Value <<= 2.718281828459;
+    Value <<= M_E;
     m_aSecondStruct.Value = Value;
     //XIdlClassRef ListenerType;
     m_aSecondStruct.State = PropertyState_DIRECT_VALUE;
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 7ea6de6cb00c..3ba77ed08a2d 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -324,7 +324,7 @@ SwCalc::SwCalc( SwDoc& rD )
     m_aVarTable[ aHashValue[ 0 ] ]->nValue.PutBool( false );
     m_aVarTable[ aHashValue[ 1 ] ]->nValue.PutBool( true );
     m_aVarTable[ aHashValue[ 2 ] ]->nValue.PutDouble( M_PI );
-    m_aVarTable[ aHashValue[ 3 ] ]->nValue.PutDouble( 2.7182818284590452354 );
+    m_aVarTable[ aHashValue[ 3 ] ]->nValue.PutDouble( M_E );
 
     for( n = 0; n < 3; ++n )
         m_aVarTable[ aHashValue[ n + 4 ] ]->nValue.PutLong( 
rDocStat.*aDocStat1[ n ]  );
diff --git a/testtools/source/bridgetest/bridgetest.cxx 
b/testtools/source/bridgetest/bridgetest.cxx
index 7c646b59a257..a685721d77bd 100644
--- a/testtools/source/bridgetest/bridgetest.cxx
+++ b/testtools/source/bridgetest/bridgetest.cxx
@@ -18,6 +18,7 @@
  */
 
 
+#include <sal/config.h>
 #include <stdio.h>
 #include <string.h>
 #include <string_view>
@@ -57,6 +58,7 @@
 #include "multi.hxx"
 #include <memory>
 #include <utility>
+#include <cmath>
 
 using namespace osl;
 using namespace cppu;
@@ -376,7 +378,7 @@ static bool performTest(
         assign(
             static_cast<TestElement &>(aData), true, '@', 17, 0x1234, 0xFEDC,
             0x12345678, 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
-            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
+            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, M_PI,
             TestEnum_LOLA, STRING_TEST_CONSTANT, 18, 0x5678, xI,
             Any(&xI, cppu::UnoType<XInterface>::get()));
         bRet &= check(aData.Any == xI, "### unexpected any!");
@@ -732,19 +734,19 @@ static bool performTest(
         assign(
             _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 
0xFEDCBA98,
             SAL_CONST_INT64(0x123456789ABCDEF0),
-            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
+            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, M_PI,
             TestEnum_LOLA, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[0],
             Any(&_arObj[0], cppu::UnoType<XInterface>::get()));
         assign(
             _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 
0xFEDCBA98,
             SAL_CONST_INT64(0x123456789ABCDEF0),
-            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
+            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, M_PI,
             TestEnum_TWO, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[1],
             Any(&_arObj[1], cppu::UnoType<XInterface>::get()));
         assign(
             _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 
0xFEDCBA98,
             SAL_CONST_INT64(0x123456789ABCDEF0),
-            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
+            SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, M_PI,
             TestEnum_CHECK, STRING_TEST_CONSTANT, 18, 0x5678, _arObj[2],
             Any(&_arObj[2], cppu::UnoType<XInterface>::get()));
         {
diff --git a/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx 
b/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx
index ad21e3963bd8..04d9b3066f62 100644
--- a/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx
+++ b/testtools/source/bridgetest/cli/cli_cpp_bridgetest.cxx
@@ -24,6 +24,7 @@
 #using <cli_uretypes.dll>
 #using <cli_ure.dll>
 #using <cli_types_bridgetest.dll>
+#include <cmath>
 
 using namespace System;
 using namespace System::Diagnostics;
@@ -375,7 +376,7 @@ static bool performTest(XBridgeTest* xLBT)
         assign( static_cast<TestElement*>(aData),
                 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
                 0x123456789abcdef0, 0xfedcba9876543210,
-                17.0815f, 3.1415926359, TestEnum::LOLA,
+                17.0815f, M_PI, TestEnum::LOLA,
                 Constants::STRING_TEST_CONSTANT, xI,
                 aAny);
 
@@ -650,15 +651,15 @@ static bool performSequenceTest(XBridgeTest* xBT)
     arStruct[0] = new TestElement(); arStruct[1] = new TestElement();
     arStruct[2] = new TestElement();
     assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
-             0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
+             0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
             TestEnum::LOLA, Constants::STRING_TEST_CONSTANT, 18, 0x5678, 
arObject[0],
             Any( __typeof(Object),  arObject[0]) );
     assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
-            0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
+            0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
             TestEnum::TWO, Constants::STRING_TEST_CONSTANT, 18, 0x5678, 
arObject[1],
             Any( __typeof(Object), arObject[1]) );
     assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
-            0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359,
+            0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
             TestEnum::CHECK, Constants::STRING_TEST_CONSTANT, 18, 0x5678, 
arObject[2],
             Any( __typeof(Object), arObject[2] ) );
     {
diff --git a/vcl/source/gdi/gradient.cxx b/vcl/source/gdi/gradient.cxx
index cf751abffa97..b4e7db904a29 100644
--- a/vcl/source/gdi/gradient.cxx
+++ b/vcl/source/gdi/gradient.cxx
@@ -21,6 +21,7 @@
 
 #include <vcl/gradient.hxx>
 #include <vcl/metaact.hxx>
+#include <cmath>
 
 class Gradient::Impl
 {
@@ -250,8 +251,8 @@ void Gradient::GetBoundRect( const tools::Rectangle& rRect, 
tools::Rectangle& rB
         else if( GetStyle() == GradientStyle::Elliptical )
         {
             // Calculation of radii for ellipse
-            aSize.setWidth( static_cast<tools::Long>( 0.5 + 
static_cast<double>(aSize.Width())  * 1.4142 ) );
-            aSize.setHeight( static_cast<tools::Long>( 0.5 + 
static_cast<double>(aSize.Height()) * 1.4142 ) );
+            aSize.setWidth( static_cast<tools::Long>( 0.5 + 
static_cast<double>(aSize.Width())  * M_SQRT2 ) );
+            aSize.setHeight( static_cast<tools::Long>( 0.5 + 
static_cast<double>(aSize.Height()) * M_SQRT2) );
         }
 
         // Calculate new centers

Reply via email to