chart2/source/view/charttypes/PieChart.cxx       |   28 ++++-------------------
 chart2/source/view/charttypes/VSeriesPlotter.cxx |   16 +++----------
 2 files changed, 9 insertions(+), 35 deletions(-)

New commits:
commit dc8c295605d190d0fc9d4a9a8b369c319be9d44b
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Jan 25 08:58:43 2024 -0500
Commit:     Taichi Haradaguchi <20001...@ymail.ne.jp>
CommitDate: Sun Jan 28 06:18:59 2024 +0100

    chart2: use std::clamp
    
    Change-Id: I9fab21a889587e1eaf709e6bd31d0a0d6078c8f9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162586
    Reviewed-by: Justin Luth <jl...@mail.com>
    Tested-by: Jenkins

diff --git a/chart2/source/view/charttypes/PieChart.cxx 
b/chart2/source/view/charttypes/PieChart.cxx
index efbef5a083eb..5e3a6dcaad17 100644
--- a/chart2/source/view/charttypes/PieChart.cxx
+++ b/chart2/source/view/charttypes/PieChart.cxx
@@ -506,17 +506,8 @@ void PieChart::createTextLabelShape(
         {
             sal_Int32 nX1 = aPieLabelInfo.aOuterPosition.getX();
             sal_Int32 nY1 = aPieLabelInfo.aOuterPosition.getY();
-            sal_Int32 nX2 = nX1;
-            sal_Int32 nY2 = nY1;
-            if (nX1 < aRect.getMinX())
-                nX2 = aRect.getMinX();
-            else if (nX1 > aRect.getMaxX())
-                nX2 = aRect.getMaxX();
-
-            if (nY1 < aRect.getMinY())
-                nY2 = aRect.getMinY();
-            else if (nY1 > aRect.getMaxY())
-                nY2 = aRect.getMaxY();
+            const sal_Int32 nX2 = std::clamp(nX1, aRect.getMinX(), 
aRect.getMaxX());
+            const sal_Int32 nY2 = std::clamp(nY1, aRect.getMinY(), 
aRect.getMaxY());
 
             const sal_Int32 nLabelSquaredDistanceFromOrigin
                 = (nX2 - aOrigin.X) * (nX2 - aOrigin.X) + (nY2 - aOrigin.Y) * 
(nY2 - aOrigin.Y);
@@ -1286,20 +1277,11 @@ void PieChart::rearrangeLabelToAvoidOverlapIfRequested( 
const awt::Size& rPageSi
     {
         if( labelInfo.bMoved && labelInfo.bShowLeaderLine )
         {
+            const basegfx::B2IRectangle 
aRect(lcl_getRect(labelInfo.xLabelGroupShape));
             sal_Int32 nX1 = labelInfo.aOuterPosition.getX();
             sal_Int32 nY1 = labelInfo.aOuterPosition.getY();
-            sal_Int32 nX2 = nX1;
-            sal_Int32 nY2 = nY1;
-            ::basegfx::B2IRectangle aRect( lcl_getRect( 
labelInfo.xLabelGroupShape ) );
-            if( nX1 < aRect.getMinX() )
-                nX2 = aRect.getMinX();
-            else if( nX1 > aRect.getMaxX() )
-                nX2 = aRect.getMaxX();
-
-            if( nY1 < aRect.getMinY() )
-                nY2 = aRect.getMinY();
-            else if( nY1 > aRect.getMaxY() )
-                nY2 = aRect.getMaxY();
+            const sal_Int32 nX2 = std::clamp(nX1, aRect.getMinX(), 
aRect.getMaxX());
+            const sal_Int32 nY2 = std::clamp(nY1, aRect.getMinY(), 
aRect.getMaxY());
 
             //when the line is very short compared to the page size don't 
create one
             ::basegfx::B2DVector aLength(nX1-nX2, nY1-nY2);
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx 
b/chart2/source/view/charttypes/VSeriesPlotter.cxx
index ef13248bf0a6..f3a3a8bebd61 100644
--- a/chart2/source/view/charttypes/VSeriesPlotter.cxx
+++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx
@@ -707,20 +707,12 @@ rtl::Reference<SvxShapeText> 
VSeriesPlotter::createDataLabel( const rtl::Referen
                     // "ShowCustomLeaderLines"
                     rDataSeries.getModel()->getFastPropertyValue( 
PROP_DATASERIES_SHOW_CUSTOM_LEADERLINES ).get<sal_Bool>())
                 {
+                    const basegfx::B2IRectangle aRect(
+                        BaseGFXHelper::makeRectangle(aRelPos, 
xTextShape->getSize()));
                     sal_Int32 nX1 = rScreenPosition2D.X;
                     sal_Int32 nY1 = rScreenPosition2D.Y;
-                    sal_Int32 nX2 = nX1;
-                    sal_Int32 nY2 = nY1;
-                    ::basegfx::B2IRectangle 
aRect(BaseGFXHelper::makeRectangle(aRelPos, xTextShape->getSize()));
-                    if (nX1 < aRelPos.X)
-                        nX2 = aRelPos.X;
-                    else if (nX1 > aRect.getMaxX())
-                        nX2 = aRect.getMaxX();
-
-                    if (nY1 < aRect.getMinY())
-                        nY2 = aRect.getMinY();
-                    else if (nY1 > aRect.getMaxY())
-                        nY2 = aRect.getMaxY();
+                    const sal_Int32 nX2 = std::clamp(nX1, aRelPos.X, 
aRect.getMaxX());
+                    const sal_Int32 nY2 = std::clamp(nY1, aRect.getMinY(), 
aRect.getMaxY());
 
                     //when the line is very short compared to the page size 
don't create one
                     ::basegfx::B2DVector aLength(nX1 - nX2, nY1 - nY2);

Reply via email to