From 8c48d69f06ddb3cb6c807a1e7db62dddb9778ded Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sat, 4 Aug 2018 10:37:17 +0300 Subject: Use more basegfx deg<->rad functions, instead of direct formulas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also make the functions constexpr. Due to slight changes in floating-point arithmetics (90.0 instead of 180.0, M_PI2 instead of M_PI resp.), results might differ in last digits (usually 17th decimal digit). This has lead to need to tweak char2dump's PieChartTest unit test. Change-Id: I20323dd7dab27e4deb408ea4181e390cc05e7cd3 Reviewed-on: https://gerrit.libreoffice.org/58583 Tested-by: Jenkins Reviewed-by: Tamás Zolnai Reviewed-by: Mike Kaganski --- basegfx/source/curve/b2dcubicbezier.cxx | 3 ++- basegfx/source/matrix/b2dhommatrix.cxx | 2 +- basegfx/source/polygon/b2dlinegeometry.cxx | 2 +- basegfx/source/polygon/b2dsvgpolypolygon.cxx | 5 +++-- basegfx/test/basegfx2d.cxx | 16 ++++++++-------- 5 files changed, 15 insertions(+), 13 deletions(-) (limited to 'basegfx') diff --git a/basegfx/source/curve/b2dcubicbezier.cxx b/basegfx/source/curve/b2dcubicbezier.cxx index db2c7baed0b1..c0adc5a09b37 100644 --- a/basegfx/source/curve/b2dcubicbezier.cxx +++ b/basegfx/source/curve/b2dcubicbezier.cxx @@ -532,7 +532,8 @@ namespace basegfx if(isBezier()) { // use support method #i37443# and allow unsharpen the criteria - ImpSubDivAngleStart(maStartPoint, maControlPointA, maControlPointB, maEndPoint, rTarget, fAngleBound * F_PI180); + ImpSubDivAngleStart(maStartPoint, maControlPointA, maControlPointB, maEndPoint, rTarget, + deg2rad(fAngleBound)); } else { diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx index 053ca89d02de..1e991304a4f0 100644 --- a/basegfx/source/matrix/b2dhommatrix.cxx +++ b/basegfx/source/matrix/b2dhommatrix.cxx @@ -282,7 +282,7 @@ namespace basegfx { // there is - 180 degree rotated rScale *= -1; - rRotate = 180*F_PI180; + rRotate = M_PI; } } else diff --git a/basegfx/source/polygon/b2dlinegeometry.cxx b/basegfx/source/polygon/b2dlinegeometry.cxx index d9c24377a16e..ca4b88238383 100644 --- a/basegfx/source/polygon/b2dlinegeometry.cxx +++ b/basegfx/source/polygon/b2dlinegeometry.cxx @@ -104,7 +104,7 @@ namespace basegfx // from that vector, take the needed rotation and add rotate for arrow to transformation const B2DVector aTargetDirection(aHead - aTail); - const double fRotation(atan2(aTargetDirection.getY(), aTargetDirection.getX()) + (90.0 * F_PI180)); + const double fRotation(atan2(aTargetDirection.getY(), aTargetDirection.getX()) + F_PI2); // rotate around docking position aArrowTransform.rotate(fRotation); diff --git a/basegfx/source/polygon/b2dsvgpolypolygon.cxx b/basegfx/source/polygon/b2dsvgpolypolygon.cxx index 4522ec94f99b..2de0daf1e82f 100644 --- a/basegfx/source/polygon/b2dsvgpolypolygon.cxx +++ b/basegfx/source/polygon/b2dsvgpolypolygon.cxx @@ -489,7 +489,8 @@ namespace basegfx // |y1'| = |-sin phi cos phi| |(y1 - y2)/2| const B2DPoint p1(nLastX, nLastY); const B2DPoint p2(nX, nY); - B2DHomMatrix aTransform(basegfx::utils::createRotateB2DHomMatrix(-fPhi*M_PI/180)); + B2DHomMatrix aTransform(basegfx::utils::createRotateB2DHomMatrix( + -deg2rad(fPhi))); const B2DPoint p1_prime( aTransform * B2DPoint(((p1-p2)/2.0)) ); @@ -581,7 +582,7 @@ namespace basegfx aTransform = basegfx::utils::createScaleB2DHomMatrix(fRX, fRY); aTransform.translate(aCenter_prime.getX(), aCenter_prime.getY()); - aTransform.rotate(fPhi*M_PI/180); + aTransform.rotate(deg2rad(fPhi)); const B2DPoint aOffset((p1+p2)/2.0); aTransform.translate(aOffset.getX(), aOffset.getY()); diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx index 82131b417b23..acc28f91014b 100644 --- a/basegfx/test/basegfx2d.cxx +++ b/basegfx/test/basegfx2d.cxx @@ -234,7 +234,7 @@ public: void rotate() { B2DHomMatrix mat; - mat.rotate(90*F_PI180); + mat.rotate(F_PI2); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate pi/2 yields exact matrix", 0.0, mat.get(0,0), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( @@ -247,7 +247,7 @@ public: "rotate pi/2 yields exact matrix", 0.0, mat.get(1,1), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate pi/2 yields exact matrix", 0.0, mat.get(1,2), 1E-12); - mat.rotate(90*F_PI180); + mat.rotate(F_PI2); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate pi yields exact matrix", -1.0, mat.get(0,0), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( @@ -260,7 +260,7 @@ public: "rotate pi yields exact matrix", -1.0, mat.get(1,1), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate pi yields exact matrix", 0.0, mat.get(1,2), 1E-12); - mat.rotate(90*F_PI180); + mat.rotate(F_PI2); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate 3/2 pi yields exact matrix", 0.0, mat.get(0,0), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( @@ -273,7 +273,7 @@ public: "rotate 3/2 pi yields exact matrix", 0.0, mat.get(1,1), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate 3/2 pi yields exact matrix", 0.0, mat.get(1,2), 1E-12); - mat.rotate(90*F_PI180); + mat.rotate(F_PI2); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "rotate 2 pi yields exact matrix", 1.0, mat.get(0,0), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( @@ -407,8 +407,8 @@ public: // are just the two rightmost values and uncritical static double fSX(10.0); static double fSY(12.0); - static double fR(45.0 * F_PI180); - static double fS(15.0 * F_PI180); + static double fR(F_PI4); + static double fS(deg2rad(15.0)); // check all possible scaling combinations CPPUNIT_ASSERT_MESSAGE("decompose: error test A1", impDecomposeComposeTest(fSX, fSY, 0.0, 0.0)); @@ -468,7 +468,7 @@ public: B2DHomMatrix aTest=utils::createScaleShearXRotateTranslateB2DHomMatrix( 6425,3938, 0, - 180*F_PI180, + F_PI, 10482,4921); // decompose that matrix B2DTuple aDScale; @@ -479,7 +479,7 @@ public: CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 6425.0, aDScale.getX(), 1E-12); CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 3938.0, aDScale.getY(), 1E-12); CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans.getX() == 10482 && aDTrans.getY() == 4921); - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", 180*F_PI180, fDRot, 1E-12 ); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", F_PI, fDRot, 1E-12 ); } // Change the following lines only, if you add, remove or rename -- cgit