tdf#123504: 0 and 360 are different angles in charts

This partly reverts commit 81302f33073e7629d724ed269f1fa21dad29e141.

Change-Id: I40cbe739eb4497b8217aca56a2c3661ed1e491f4
Reviewed-on: https://gerrit.libreoffice.org/69440
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/chart2/qa/extras/chart2dump/chart2dump.cxx b/chart2/qa/extras/chart2dump/chart2dump.cxx
index 030fb92..4e91eeb 100644
--- a/chart2/qa/extras/chart2dump/chart2dump.cxx
+++ b/chart2/qa/extras/chart2dump/chart2dump.cxx
@@ -855,7 +855,8 @@ DECLARE_DUMP_TEST(PieChartTest, Chart2DumpTest, false)
        "rotated_pie_chart.ods",
        "exploded_pie_chart.ods",
        "donut_chart.ods",
        "pie_chart_many_slices.ods"
        "pie_chart_many_slices.ods",
        "pie_chart_100_and_0.ods",
    };

    for (const OUString& sTestFile : aTestFiles)
diff --git a/chart2/qa/extras/chart2dump/data/pie_chart_100_and_0.ods b/chart2/qa/extras/chart2dump/data/pie_chart_100_and_0.ods
new file mode 100644
index 0000000..a6ff5d6
--- /dev/null
+++ b/chart2/qa/extras/chart2dump/data/pie_chart_100_and_0.ods
Binary files differ
diff --git a/chart2/qa/extras/chart2dump/reference/piecharttest/pie_chart_100_and_0.txt b/chart2/qa/extras/chart2dump/reference/piecharttest/pie_chart_100_and_0.txt
new file mode 100644
index 0000000..40db143
--- /dev/null
+++ b/chart2/qa/extras/chart2dump/reference/piecharttest/pie_chart_100_and_0.txt
@@ -0,0 +1,20 @@
// nSeriesCount
1
/// Series 0 slices
// nSlicesCountInSeries
1
/// /D=0:CS=0:CT=0:Series=0:Point=0
// aSlicePosition.X
3210
// aSlicePosition.Y
180
// aSliceSize.Height
8639
// aSliceSize.Width
8639
// aSliceTransformation
8639;0;3210;0;8639;180;0;0;1
// static_cast<sal_Int32>(aSliceFillStyle)
1
// static_cast<sal_Int32>(aSliceFillColor)
17798
\ No newline at end of file
diff --git a/chart2/source/view/main/PlottingPositionHelper.cxx b/chart2/source/view/main/PlottingPositionHelper.cxx
index 2382894..c2c2d25 100644
--- a/chart2/source/view/main/PlottingPositionHelper.cxx
+++ b/chart2/source/view/main/PlottingPositionHelper.cxx
@@ -32,7 +32,6 @@
#include <com/sun/star/drawing/XShapes.hpp>

#include <rtl/math.hxx>
#include <tools/helpers.hxx>

namespace chart
{
@@ -417,10 +416,11 @@ double PolarPlottingPositionHelper::getWidthAngleDegree( double& fStartLogicValu
        && !::rtl::math::approxEqual( fStartLogicValueOnAngleAxis, fEndLogicValueOnAngleAxis ) )
        fWidthAngleDegree = 360.0;

    while(fWidthAngleDegree<0.0)
        fWidthAngleDegree+=360.0;
    while(fWidthAngleDegree>360.0)
        fWidthAngleDegree-=360.0;
    // tdf#123504: both 0 and 360 are valid and different values here!
    while (fWidthAngleDegree < 0.0)
        fWidthAngleDegree += 360.0;
    while (fWidthAngleDegree > 360.0)
        fWidthAngleDegree -= 360.0;

    return fWidthAngleDegree;
}
@@ -473,7 +473,12 @@ double PolarPlottingPositionHelper::transformToAngleDegree( double fLogicValueOn
    fRet = m_fAngleDegreeOffset
                  + fAxisAngleScaleDirection*(fScaledLogicAngleValue-MinAngleValue)*360.0
                    /fabs(MaxAngleValue-MinAngleValue);
    return NormAngle360(fRet);
    // tdf#123504: both 0 and 360 are valid and different values here!
    while (fRet > 360.0)
        fRet -= 360.0;
    while (fRet < 0)
        fRet += 360.0;
    return fRet;
}

/**
diff --git a/chart2/source/view/main/PolarLabelPositionHelper.cxx b/chart2/source/view/main/PolarLabelPositionHelper.cxx
index 6cea12f..a3e9a7c 100644
--- a/chart2/source/view/main/PolarLabelPositionHelper.cxx
+++ b/chart2/source/view/main/PolarLabelPositionHelper.cxx
@@ -24,8 +24,6 @@

#include <com/sun/star/chart/DataLabelPlacement.hpp>

#include <tools/helpers.hxx>

namespace chart
{
using namespace ::com::sun::star;
@@ -123,7 +121,11 @@ awt::Point PolarLabelPositionHelper::getLabelScreenPositionAndAlignmentForUnitCi
    //set LabelAlignment
    if( !bCenter )
    {
        fAngleDegree = NormAngle360(fAngleDegree);
        // tdf#123504: both 0 and 360 are valid and different values here!
        while (fAngleDegree > 360.0)
            fAngleDegree -= 360.0;
        while (fAngleDegree < 0.0)
            fAngleDegree += 360.0;

        bool bOutside = nLabelPlacement == css::chart::DataLabelPlacement::OUTSIDE;

diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx
index 76db679..a297f3c 100644
--- a/chart2/source/view/main/ShapeFactory.cxx
+++ b/chart2/source/view/main/ShapeFactory.cxx
@@ -870,7 +870,11 @@ uno::Reference< drawing::XShape >
    if( !xTarget.is() )
        return nullptr;

    fUnitCircleWidthAngleDegree = NormAngle360(fUnitCircleWidthAngleDegree);
    // tdf#123504: both 0 and 360 are valid and different values here!
    while (fUnitCircleWidthAngleDegree > 360)
        fUnitCircleWidthAngleDegree -= 360.0;
    while (fUnitCircleWidthAngleDegree < 0)
        fUnitCircleWidthAngleDegree += 360.0;

    //create shape
    uno::Reference< drawing::XShape > xShape(
@@ -919,9 +923,10 @@ uno::Reference< drawing::XShape >
    if( !xTarget.is() )
        return nullptr;

    while(fUnitCircleWidthAngleDegree>360)
    // tdf#123504: both 0 and 360 are valid and different values here!
    while (fUnitCircleWidthAngleDegree > 360)
        fUnitCircleWidthAngleDegree -= 360.0;
    while(fUnitCircleWidthAngleDegree<0)
    while (fUnitCircleWidthAngleDegree < 0)
        fUnitCircleWidthAngleDegree += 360.0;

    //create shape