diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-03 13:05:24 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-03 21:57:23 +0200 |
commit | 81302f33073e7629d724ed269f1fa21dad29e141 (patch) | |
tree | 59c1a5422fee301751c170e6ea24a3ca9b0caddc /chart2 | |
parent | 83b25e4b9fa8f95c24759a64f8cb9716ee34a4a3 (diff) |
Move angle normalization code from various places to tools
Also rename svx angle normalization functions in include/svx/svdtrans.hxx, that
deal with 100ths of degree, to avoid confusion: NormAngle180 -> NormAngle18000;
NormAngle360 -> NormAngle36000.
Some places were fixed that previously returned inclusive ranges (i.e., both 0
and 360), see changes in these files:
chart2/source/view/main/PlottingPositionHelper.cxx
chart2/source/view/main/PolarLabelPositionHelper.cxx
chart2/source/view/main/ShapeFactory.cxx
filter/source/graphicfilter/idxf/dxf2mtf.cxx
sw/source/core/graphic/grfatr.cxx
(the latter now matches the comment in the function).
Change-Id: I9f274bbb4168360d60dceff02aeba6332c519a59
Reviewed-on: https://gerrit.libreoffice.org/58556
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx | 23 | ||||
-rw-r--r-- | chart2/source/tools/ThreeDHelper.cxx | 27 | ||||
-rw-r--r-- | chart2/source/view/charttypes/PieChart.cxx | 23 | ||||
-rw-r--r-- | chart2/source/view/main/AbstractShapeFactory.cxx | 6 | ||||
-rw-r--r-- | chart2/source/view/main/PlottingPositionHelper.cxx | 7 | ||||
-rw-r--r-- | chart2/source/view/main/PolarLabelPositionHelper.cxx | 7 | ||||
-rw-r--r-- | chart2/source/view/main/ShapeFactory.cxx | 6 |
7 files changed, 28 insertions, 71 deletions
diff --git a/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx b/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx index ae8449dcf257..acc07bc386d9 100644 --- a/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx +++ b/chart2/source/controller/dialogs/tp_3D_SceneGeometry.cxx @@ -27,6 +27,7 @@ #include <editeng/unoprnms.hxx> #include <com/sun/star/drawing/ProjectionMode.hpp> #include <tools/diagnose_ex.h> +#include <tools/helpers.hxx> namespace chart { @@ -36,15 +37,6 @@ using namespace ::com::sun::star; namespace { -void lcl_shiftAngleToValidRange( sal_Int64& rnAngleDegree ) -{ - //valid range: ]-180,180] - while( rnAngleDegree<=-180 ) - rnAngleDegree+=360; - while( rnAngleDegree>180 ) - rnAngleDegree-=360; -} - void lcl_SetMetricFieldLimits( MetricField& rField, sal_Int64 nLimit ) { rField.SetMin(-1*nLimit); @@ -87,13 +79,12 @@ ThreeD_SceneGeometry_TabPage::ThreeD_SceneGeometry_TabPage( vcl::Window* pWindow lcl_SetMetricFieldLimits( *m_pMFZRotation, 90 ); - m_nXRotation = ::basegfx::fround(fXAngle*pow(10.0,m_pMFXRotation->GetDecimalDigits())); - m_nYRotation = ::basegfx::fround(-1.0*fYAngle*pow(10.0,m_pMFYRotation->GetDecimalDigits())); - m_nZRotation = ::basegfx::fround(-1.0*fZAngle*pow(10.0,m_pMFZRotation->GetDecimalDigits())); - - lcl_shiftAngleToValidRange( m_nXRotation ); - lcl_shiftAngleToValidRange( m_nYRotation ); - lcl_shiftAngleToValidRange( m_nZRotation ); + m_nXRotation = NormAngle180( + ::basegfx::fround(fXAngle * pow(10.0, m_pMFXRotation->GetDecimalDigits()))); + m_nYRotation = NormAngle180( + ::basegfx::fround(-1.0 * fYAngle * pow(10.0, m_pMFYRotation->GetDecimalDigits()))); + m_nZRotation = NormAngle180( + ::basegfx::fround(-1.0 * fZAngle * pow(10.0, m_pMFZRotation->GetDecimalDigits()))); m_pMFXRotation->SetValue(m_nXRotation); m_pMFYRotation->SetValue(m_nYRotation); diff --git a/chart2/source/tools/ThreeDHelper.cxx b/chart2/source/tools/ThreeDHelper.cxx index 25da0b374de3..3967ce42868d 100644 --- a/chart2/source/tools/ThreeDHelper.cxx +++ b/chart2/source/tools/ThreeDHelper.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/drawing/ShadeMode.hpp> #include <tools/diagnose_ex.h> +#include <tools/helpers.hxx> #include <sal/log.hxx> namespace chart @@ -369,24 +370,6 @@ double lcl_shiftAngleToIntervalMinusPiToPi( double fAngleRad ) return fAngleRad; } -void lcl_shiftAngleToIntervalMinus180To180( sal_Int32& rnAngleDegree ) -{ - //valid range: ]-180,180] - while( rnAngleDegree<=-180 ) - rnAngleDegree+=360; - while( rnAngleDegree>180 ) - rnAngleDegree-=360; -} - -void lcl_shiftAngleToIntervalZeroTo360( sal_Int32& rnAngleDegree ) -{ - //valid range: [0,360[ - while( rnAngleDegree<0 ) - rnAngleDegree+=360; - while( rnAngleDegree>=360 ) - rnAngleDegree-=360; -} - void lcl_ensureIntervalMinus1To1( double& rSinOrCos ) { if (rSinOrCos < -1.0) @@ -414,8 +397,8 @@ void ThreeDHelper::convertElevationRotationDegToXYZAngleRad( //https://bz.apache.org/ooo/show_bug.cgi?id=72994 //https://bz.apache.org/ooo/attachment.cgi?id=50608 - lcl_shiftAngleToIntervalZeroTo360( nElevationDeg ); - lcl_shiftAngleToIntervalZeroTo360( nRotationDeg ); + nElevationDeg = NormAngle360(nElevationDeg); + nRotationDeg = NormAngle360(nRotationDeg); double& x = rfXAngleRad; double& y = rfYAngleRad; @@ -1053,8 +1036,8 @@ void ThreeDHelper::getRotationFromDiagram( const uno::Reference< beans::XPropert // nZRotation = basegfx::fround(-1.0 * basegfx::rad2deg(fZAngle)); } - lcl_shiftAngleToIntervalMinus180To180( rnHorizontalAngleDegree ); - lcl_shiftAngleToIntervalMinus180To180( rnVerticalAngleDegree ); + rnHorizontalAngleDegree = NormAngle180(rnHorizontalAngleDegree); + rnVerticalAngleDegree = NormAngle180(rnVerticalAngleDegree); } void ThreeDHelper::setRotationToDiagram( const uno::Reference< beans::XPropertySet >& xSceneProperties diff --git a/chart2/source/view/charttypes/PieChart.cxx b/chart2/source/view/charttypes/PieChart.cxx index de48a1d5e893..19f978ee8301 100644 --- a/chart2/source/view/charttypes/PieChart.cxx +++ b/chart2/source/view/charttypes/PieChart.cxx @@ -33,6 +33,7 @@ #include <com/sun/star/container/XChild.hpp> #include <rtl/math.hxx> #include <sal/log.hxx> +#include <tools/helpers.hxx> #include <memory> @@ -759,16 +760,6 @@ double lcl_degToRad(double fAngleDeg) return (fAngleDeg / 180) * M_PI; } -inline -double lcl_getDegAngleInStandardRange(double fAngle) -{ - while( fAngle < 0.0 ) - fAngle += 360.0; - while( fAngle >= 360.0 ) - fAngle -= 360.0; - return fAngle; -} - }//end anonymous namespace PieChart::PieLabelInfo::PieLabelInfo() @@ -1277,10 +1268,10 @@ bool PieChart::performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLab "** PieChart::performLabelBestFitInnerPlacement invoked **" ); // get pie slice properties - double fStartAngleDeg = lcl_getDegAngleInStandardRange(rShapeParam.mfUnitCircleStartAngleDegree); + double fStartAngleDeg = NormAngle360(rShapeParam.mfUnitCircleStartAngleDegree); double fWidthAngleDeg = rShapeParam.mfUnitCircleWidthAngleDegree; double fHalfWidthAngleDeg = fWidthAngleDeg / 2.0; - double fBisectingRayAngleDeg = lcl_getDegAngleInStandardRange(fStartAngleDeg + fHalfWidthAngleDeg); + double fBisectingRayAngleDeg = NormAngle360(fStartAngleDeg + fHalfWidthAngleDeg); // get the middle point of the arc representing the pie slice border double fLogicZ = rShapeParam.mfLogicZ + 1.0; @@ -1334,7 +1325,7 @@ bool PieChart::performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLab double fLabelHeight = aBb.getHeight(); // -45 <= fAlphaDeg < 315 - double fAlphaDeg = lcl_getDegAngleInStandardRange(fBisectingRayAngleDeg + 45) - 45; + double fAlphaDeg = NormAngle360(fBisectingRayAngleDeg + 45) - 45; double fAlphaRad = lcl_degToRad(fAlphaDeg); // compute nearest edge index @@ -1507,7 +1498,7 @@ bool PieChart::performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLab // check the angle between CP and CM double fAngleRad = aPositionalVector.angle(aVertexM); - double fAngleDeg = lcl_getDegAngleInStandardRange( lcl_radToDeg(fAngleRad) ); + double fAngleDeg = NormAngle360(lcl_radToDeg(fAngleRad)); if( fAngleDeg > 180 ) // in case the wrong angle has been computed fAngleDeg = 360 - fAngleDeg; SAL_INFO( "chart2.pie.label.bestfit.inside", @@ -1522,7 +1513,7 @@ bool PieChart::performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLab { // check the angle between CP and CN fAngleRad = aPositionalVector.angle(aNearestVertex); - fAngleDeg = lcl_getDegAngleInStandardRange( lcl_radToDeg(fAngleRad) ); + fAngleDeg = NormAngle360(lcl_radToDeg(fAngleRad)); if( fAngleDeg > 180 ) // in case the wrong angle has been computed fAngleDeg = 360 - fAngleDeg; SAL_INFO( "chart2.pie.label.bestfit.inside", @@ -1536,7 +1527,7 @@ bool PieChart::performLabelBestFitInnerPlacement(ShapeParam& rShapeParam, PieLab { // check the angle between CP and CG fAngleRad = aPositionalVector.angle(aVertexG); - fAngleDeg = lcl_getDegAngleInStandardRange( lcl_radToDeg(fAngleRad) ); + fAngleDeg = NormAngle360(lcl_radToDeg(fAngleRad)); if( fAngleDeg > 180 ) // in case the wrong angle has been computed fAngleDeg = 360 - fAngleDeg; SAL_INFO( "chart2.pie.label.bestfit.inside", diff --git a/chart2/source/view/main/AbstractShapeFactory.cxx b/chart2/source/view/main/AbstractShapeFactory.cxx index df2516ab82f2..6e85eb79a9ce 100644 --- a/chart2/source/view/main/AbstractShapeFactory.cxx +++ b/chart2/source/view/main/AbstractShapeFactory.cxx @@ -32,6 +32,7 @@ #include <editeng/unoprnms.hxx> #include <rtl/math.hxx> +#include <tools/helpers.hxx> #include <tools/svlibrary.h> #include <svx/svdocirc.hxx> #include <svx/svdopath.hxx> @@ -262,10 +263,7 @@ awt::Size AbstractShapeFactory::getSizeAfterRotation( aRet = aSize; else { - while(fRotationAngleDegree>=360.0) - fRotationAngleDegree-=360.0; - while(fRotationAngleDegree<0.0) - fRotationAngleDegree+=360.0; + fRotationAngleDegree = NormAngle360(fRotationAngleDegree); if(fRotationAngleDegree>270.0) fRotationAngleDegree=360.0-fRotationAngleDegree; else if(fRotationAngleDegree>180.0) diff --git a/chart2/source/view/main/PlottingPositionHelper.cxx b/chart2/source/view/main/PlottingPositionHelper.cxx index 9ad4f4465e53..da5cc4159aca 100644 --- a/chart2/source/view/main/PlottingPositionHelper.cxx +++ b/chart2/source/view/main/PlottingPositionHelper.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/drawing/XShapes.hpp> #include <rtl/math.hxx> +#include <tools/helpers.hxx> namespace chart { @@ -477,11 +478,7 @@ double PolarPlottingPositionHelper::transformToAngleDegree( double fLogicValueOn fRet = m_fAngleDegreeOffset + fAxisAngleScaleDirection*(fScaledLogicAngleValue-MinAngleValue)*360.0 /fabs(MaxAngleValue-MinAngleValue); - while(fRet>360.0) - fRet-=360.0; - while(fRet<0) - fRet+=360.0; - return fRet; + return NormAngle360(fRet); } /** diff --git a/chart2/source/view/main/PolarLabelPositionHelper.cxx b/chart2/source/view/main/PolarLabelPositionHelper.cxx index 052994c2c109..07bf9e8bae85 100644 --- a/chart2/source/view/main/PolarLabelPositionHelper.cxx +++ b/chart2/source/view/main/PolarLabelPositionHelper.cxx @@ -25,6 +25,8 @@ #include <com/sun/star/chart/DataLabelPlacement.hpp> +#include <tools/helpers.hxx> + namespace chart { using namespace ::com::sun::star; @@ -122,10 +124,7 @@ awt::Point PolarLabelPositionHelper::getLabelScreenPositionAndAlignmentForUnitCi //set LabelAlignment if( !bCenter ) { - while(fAngleDegree>360.0) - fAngleDegree-=360.0; - while(fAngleDegree<0.0) - fAngleDegree+=360.0; + fAngleDegree = NormAngle360(fAngleDegree); bool bOutside = nLabelPlacement == css::chart::DataLabelPlacement::OUTSIDE; diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index 8e3f67bb18b1..696ca39da940 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -59,6 +59,7 @@ #include <basegfx/point/b2dpoint.hxx> #include <basegfx/matrix/b3dhommatrix.hxx> #include <tools/diagnose_ex.h> +#include <tools/helpers.hxx> #include <sal/log.hxx> #include <algorithm> @@ -877,10 +878,7 @@ uno::Reference< drawing::XShape > if( !xTarget.is() ) return nullptr; - while(fUnitCircleWidthAngleDegree>360) - fUnitCircleWidthAngleDegree -= 360.0; - while(fUnitCircleWidthAngleDegree<0) - fUnitCircleWidthAngleDegree += 360.0; + fUnitCircleWidthAngleDegree = NormAngle360(fUnitCircleWidthAngleDegree); //create shape uno::Reference< drawing::XShape > xShape( |