diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-04 10:37:17 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-04 20:51:27 +0200 |
commit | 8c48d69f06ddb3cb6c807a1e7db62dddb9778ded (patch) | |
tree | 8b6bf137be41ebe93746c4958ab9106bbf5cc339 /svx/source/svdraw | |
parent | c05fbde6c870b7e6bc2f9bf642dc7d76215a496f (diff) |
Use more basegfx deg<->rad functions, instead of direct formulas
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 <tamas.zolnai@collabora.com>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'svx/source/svdraw')
-rw-r--r-- | svx/source/svdraw/gradtrns.cxx | 20 | ||||
-rw-r--r-- | svx/source/svdraw/svdoashp.cxx | 9 | ||||
-rw-r--r-- | svx/source/svdraw/svdotext.cxx | 6 |
3 files changed, 16 insertions, 19 deletions
diff --git a/svx/source/svdraw/gradtrns.cxx b/svx/source/svdraw/gradtrns.cxx index 660f94b0d61b..640636bf44c9 100644 --- a/svx/source/svdraw/gradtrns.cxx +++ b/svx/source/svdraw/gradtrns.cxx @@ -68,7 +68,7 @@ void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& r if(rG.aGradient.GetAngle()) { - const double fAngle = static_cast<double>(rG.aGradient.GetAngle()) * (F_PI180 / 10.0); + const double fAngle = basegfx::deg2rad(rG.aGradient.GetAngle() / 10.0); const basegfx::B2DHomMatrix aTransformation(basegfx::utils::createRotateAroundPoint(aCenter, -fAngle)); aStartPos *= aTransformation; @@ -91,7 +91,7 @@ void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& r if(rG.aGradient.GetAngle()) { - const double fAngle = static_cast<double>(rG.aGradient.GetAngle()) * (F_PI180 / 10.0); + const double fAngle = basegfx::deg2rad(rG.aGradient.GetAngle() / 10.0); const basegfx::B2DHomMatrix aTransformation(basegfx::utils::createRotateAroundPoint(aCenter, -fAngle)); aStartPos *= aTransformation; @@ -115,7 +115,7 @@ void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& r if(rG.aGradient.GetAngle()) { - const double fAngle = static_cast<double>(rG.aGradient.GetAngle()) * (F_PI180 / 10.0); + const double fAngle = basegfx::deg2rad(rG.aGradient.GetAngle() / 10.0); const basegfx::B2DHomMatrix aTransformation(basegfx::utils::createRotateAroundPoint(aEndPos, -fAngle)); aStartPos *= aTransformation; @@ -150,7 +150,7 @@ void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& r if(rG.aGradient.GetAngle()) { - const double fAngle = static_cast<double>(rG.aGradient.GetAngle()) * (F_PI180 / 10.0); + const double fAngle = basegfx::deg2rad(rG.aGradient.GetAngle() / 10.0); const basegfx::B2DHomMatrix aTransformation(basegfx::utils::createRotateAroundPoint(aEndPos, -fAngle)); aStartPos *= aTransformation; @@ -219,8 +219,7 @@ void GradTransformer::VecToGrad(GradTransVector const & rV, GradTransGradient& r aFullVec.normalize(); - double fNewFullAngle(atan2(aFullVec.getY(), aFullVec.getX())); - fNewFullAngle /= F_PI180; + double fNewFullAngle(basegfx::rad2deg(atan2(aFullVec.getY(), aFullVec.getX()))); fNewFullAngle *= -10.0; fNewFullAngle += 900.0; @@ -304,8 +303,7 @@ void GradTransformer::VecToGrad(GradTransVector const & rV, GradTransGradient& r } aFullVec.normalize(); - double fNewFullAngle(atan2(aFullVec.getY(), aFullVec.getX())); - fNewFullAngle /= F_PI180; + double fNewFullAngle(basegfx::rad2deg(atan2(aFullVec.getY(), aFullVec.getX()))); fNewFullAngle *= -10.0; fNewFullAngle += 900.0; @@ -400,8 +398,7 @@ void GradTransformer::VecToGrad(GradTransVector const & rV, GradTransGradient& r // angle is not definitely necessary for these modes, but it makes // controlling more fun for the user aFullVec.normalize(); - double fNewFullAngle(atan2(aFullVec.getY(), aFullVec.getX())); - fNewFullAngle /= F_PI180; + double fNewFullAngle(basegfx::rad2deg(atan2(aFullVec.getY(), aFullVec.getX()))); fNewFullAngle *= -10.0; fNewFullAngle += 900.0; @@ -496,8 +493,7 @@ void GradTransformer::VecToGrad(GradTransVector const & rV, GradTransGradient& r // angle is not definitely necessary for these modes, but it makes // controlling more fun for the user aFullVec.normalize(); - double fNewFullAngle(atan2(aFullVec.getY(), aFullVec.getX())); - fNewFullAngle /= F_PI180; + double fNewFullAngle(basegfx::rad2deg(atan2(aFullVec.getY(), aFullVec.getX()))); fNewFullAngle *= -10.0; fNewFullAngle += 900.0; diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx index 8d839abb77d5..317dd6daa40d 100644 --- a/svx/source/svdraw/svdoashp.cxx +++ b/svx/source/svdraw/svdoashp.cxx @@ -1741,7 +1741,8 @@ void SdrObjCustomShape::ImpCheckCustomGluePointsAreAdded() if ( nShearAngle ) ShearPoint( aGlue, aRef, fTan ); - RotatePoint( aGlue, aRef, sin( fObjectRotation * F_PI180 ), cos( fObjectRotation * F_PI180 ) ); + RotatePoint(aGlue, aRef, sin(basegfx::deg2rad(fObjectRotation)), + cos(basegfx::deg2rad(fObjectRotation))); if ( bMirroredX ) aGlue.setX( maRect.GetWidth() - aGlue.X() ); if ( bMirroredY ) @@ -2938,7 +2939,7 @@ void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, // #i123181# The fix for #121932# here was wrong, the trunk version does not correct the // mirrored shear values, neither at the object level, nor on the API or XML level. Taking // back the mirroring of the shear angle - aGeoStat.nShearAngle = FRound((atan(fShearX) / F_PI180) * 100.0); + aGeoStat.nShearAngle = FRound(basegfx::rad2deg(atan(fShearX)) * 100.0); aGeoStat.RecalcTan(); Shear(Point(), aGeoStat.nShearAngle, aGeoStat.nTan, false); } @@ -2967,8 +2968,8 @@ void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, bool SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& /*rPolyPolygon*/) const { // get turn and shear - double fRotate = fObjectRotation * F_PI180; - double fShearX = (aGeo.nShearAngle / 100.0) * F_PI180; + double fRotate = basegfx::deg2rad(fObjectRotation); + double fShearX = basegfx::deg2rad(aGeo.nShearAngle / 100.0); // get aRect, this is the unrotated snaprect tools::Rectangle aRectangle(maRect); diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index 54fcda68de12..b0799a92b5d8 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -1603,8 +1603,8 @@ void SdrTextObj::SetVerticalWriting(bool bVertical) bool SdrTextObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& /*rPolyPolygon*/) const { // get turn and shear - double fRotate = (aGeo.nRotationAngle / 100.0) * F_PI180; - double fShearX = (aGeo.nShearAngle / 100.0) * F_PI180; + double fRotate = basegfx::deg2rad(aGeo.nRotationAngle / 100.0); + double fShearX = basegfx::deg2rad(aGeo.nShearAngle / 100.0); // get aRect, this is the unrotated snaprect tools::Rectangle aRectangle(maRect); @@ -1690,7 +1690,7 @@ void SdrTextObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b if(!basegfx::fTools::equalZero(fShearX)) { GeoStat aGeoStat; - aGeoStat.nShearAngle = FRound((atan(fShearX) / F_PI180) * 100.0); + aGeoStat.nShearAngle = FRound(basegfx::rad2deg(atan(fShearX)) * 100.0); aGeoStat.RecalcTan(); Shear(Point(), aGeoStat.nShearAngle, aGeoStat.nTan, false); } |