include/svx/svdtrans.hxx        |    6 ++-
 svx/source/svdraw/svdoashp.cxx  |    4 +-
 svx/source/svdraw/svdotxtr.cxx  |    8 ++--
 svx/source/svdraw/svdtrans.cxx  |   73 ++++++++++++++++++++++++----------------
 svx/source/unodraw/unoshap2.cxx |    4 +-
 5 files changed, 58 insertions(+), 37 deletions(-)

New commits:
commit b070e8c0da60c4d9f27ca95847e31d8f2e1ab336
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Feb 9 21:16:55 2023 +0900
Commit:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
CommitDate: Thu Feb 9 21:16:55 2023 +0900

    svx: change Poly2Rect to return a rectangle, also clean-up the code
    
    There is no need to pass the rectangle by reference and to change
    it inside the function, better to return a new instance.
    
    Also clean-up the code of Poly2Rect and rename the function to
    svx::polygonToRectangle.
    
    Change-Id: I25e77c8abd12e2075939f55e06f40343ac23ca97

diff --git a/include/svx/svdtrans.hxx b/include/svx/svdtrans.hxx
index 0087f5407f81..dea845a26bc1 100644
--- a/include/svx/svdtrans.hxx
+++ b/include/svx/svdtrans.hxx
@@ -212,7 +212,11 @@ public:
 };
 
 tools::Polygon Rect2Poly(const tools::Rectangle& rRect, const GeoStat& rGeo);
-void Poly2Rect(const tools::Polygon& rPol, tools::Rectangle& rRect, GeoStat& 
rGeo);
+
+namespace svx
+{
+tools::Rectangle polygonToRectangle(const tools::Polygon& rPolygon, GeoStat& 
rGeo);
+}
 
 void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho);
 void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho);
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index a6a56f417e6d..63a987e172ff 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -3146,7 +3146,7 @@ bool 
SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegf
             aPol[2]=aPol0[3];
             aPol[3]=aPol0[2];
             aPol[4]=aPol0[1];
-            Poly2Rect(aPol,aRectangle,aNewGeo);
+            aRectangle = svx::polygonToRectangle(aPol, aNewGeo);
         }
         if ( bMirroredY )
         {
@@ -3169,7 +3169,7 @@ bool 
SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegf
             aPol[2]=aPol0[3]; // it was *not* wrong even when the reordering
             aPol[3]=aPol0[2]; // *seems* to be specific for X-Mirrorings. Oh
             aPol[4]=aPol0[1]; // will I be happy when this old stuff is |gone| 
with aw080 (!)
-            Poly2Rect(aPol, aRectangle, aNewGeo);
+            aRectangle = svx::polygonToRectangle(aPol, aNewGeo);
         }
     }
 
diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx
index 8ac600e3a02c..e2a83be5cb9d 100644
--- a/svx/source/svdraw/svdotxtr.cxx
+++ b/svx/source/svdraw/svdotxtr.cxx
@@ -154,7 +154,7 @@ void SdrTextObj::NbcResize(const Point& rRef, const 
Fraction& xFact, const Fract
             aPol[3] = aPol0[2];
             aPol[4] = aPol0[1];
         }
-        Poly2Rect(aPol, aRectangle, maGeo);
+        aRectangle = svx::polygonToRectangle(aPol, maGeo);
         setRectangle(aRectangle);
     }
 
@@ -224,7 +224,8 @@ void SdrTextObj::NbcShear(const Point& rRef, Degree100 
/*nAngle*/, double tn, bo
     for (sal_uInt16 i=0; i<nPointCount; i++) {
          ShearPoint(aPol[i],rRef,tn,bVShear);
     }
-    Poly2Rect(aPol, aRectangle, maGeo);
+    aRectangle = svx::polygonToRectangle(aPol, maGeo);
+
     ImpJustifyRect(aRectangle);
     setRectangle(aRectangle);
 
@@ -262,7 +263,8 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& 
rRef2)
     aPol[3]=aPol0[2];
     aPol[4]=aPol0[1];
 
-    Poly2Rect(aPol, aRectangle, maGeo);
+    aRectangle = svx::polygonToRectangle(aPol, maGeo);
+
     setRectangle(aRectangle);
 
     if (bRotate90) {
diff --git a/svx/source/svdraw/svdtrans.cxx b/svx/source/svdraw/svdtrans.cxx
index 23ce4787427e..ad44aa230e17 100644
--- a/svx/source/svdraw/svdtrans.cxx
+++ b/svx/source/svdraw/svdtrans.cxx
@@ -477,47 +477,62 @@ tools::Polygon Rect2Poly(const tools::Rectangle& rRect, 
const GeoStat& rGeo)
     return aPol;
 }
 
-void Poly2Rect(const tools::Polygon& rPol, tools::Rectangle& rRect, GeoStat& 
rGeo)
+namespace svx
 {
-    rGeo.nRotationAngle=GetAngle(rPol[1]-rPol[0]);
-    rGeo.nRotationAngle=NormAngle36000(rGeo.nRotationAngle);
+tools::Rectangle polygonToRectangle(const tools::Polygon& rPolygon, GeoStat& 
rGeo)
+{
+    rGeo.nRotationAngle = GetAngle(rPolygon[1] - rPolygon[0]);
+    rGeo.nRotationAngle = NormAngle36000(rGeo.nRotationAngle);
+
     // rotation successful
     rGeo.RecalcSinCos();
 
-    Point aPt1(rPol[1]-rPol[0]);
-    if (rGeo.nRotationAngle) 
RotatePoint(aPt1,Point(0,0),-rGeo.mfSinRotationAngle,rGeo.mfCosRotationAngle); 
// -Sin to reverse rotation
-    tools::Long nWdt=aPt1.X();
-
-    Point aPt0(rPol[0]);
-    Point aPt3(rPol[3]-rPol[0]);
-    if (rGeo.nRotationAngle) 
RotatePoint(aPt3,Point(0,0),-rGeo.mfSinRotationAngle,rGeo.mfCosRotationAngle); 
// -Sin to reverse rotation
-    tools::Long nHgt=aPt3.Y();
+    Point aPoint1(rPolygon[1] - rPolygon[0]);
+    if (rGeo.nRotationAngle)
+        RotatePoint(aPoint1, Point(0,0), -rGeo.mfSinRotationAngle, 
rGeo.mfCosRotationAngle); // -Sin to reverse rotation
+    tools::Long nWidth = aPoint1.X();
 
+    Point aPoint0(rPolygon[0]);
+    Point aPoint3(rPolygon[3] - rPolygon[0]);
+    if (rGeo.nRotationAngle)
+        RotatePoint(aPoint3, Point(0,0), -rGeo.mfSinRotationAngle, 
rGeo.mfCosRotationAngle); // -Sin to reverse rotation
+    tools::Long nHeight = aPoint3.Y();
 
-    Degree100 nShW=GetAngle(aPt3);
-    nShW-=27000_deg100; // ShearWink is measured against a vertical line
-    nShW=-nShW;  // negating, because '+' is shearing clock-wise
+    Degree100 nShearAngle = GetAngle(aPoint3);
+    nShearAngle -= 27000_deg100; // ShearWink is measured against a vertical 
line
+    nShearAngle = -nShearAngle;  // negating, because '+' is shearing 
clock-wise
 
-    bool bMirr=aPt3.Y()<0;
-    if (bMirr) { // "exchange of points" when mirroring
-        nHgt=-nHgt;
-        nShW+=18000_deg100;
-        aPt0=rPol[3];
+    bool bMirror = aPoint3.Y() < 0;
+    if (bMirror)
+    {   // "exchange of points" when mirroring
+        nHeight = -nHeight;
+        nShearAngle += 18000_deg100;
+        aPoint0 = rPolygon[3];
     }
-    nShW=NormAngle18000(nShW);
-    if (nShW<-9000_deg100 || nShW>9000_deg100) {
-        nShW=NormAngle18000(nShW+18000_deg100);
+
+    nShearAngle = NormAngle18000(nShearAngle);
+    if (nShearAngle < -9000_deg100 || nShearAngle > 9000_deg100)
+    {
+        nShearAngle = NormAngle18000(nShearAngle + 18000_deg100);
     }
-    if (nShW<-SDRMAXSHEAR) nShW=-SDRMAXSHEAR; // limit ShearWinkel (shear 
angle) to +/- 89.00 deg
-    if (nShW>SDRMAXSHEAR)  nShW=SDRMAXSHEAR;
-    rGeo.nShearAngle=nShW;
+
+    if (nShearAngle < -SDRMAXSHEAR)
+        nShearAngle = -SDRMAXSHEAR; // limit ShearWinkel (shear angle) to +/- 
89.00 deg
+
+    if (nShearAngle > SDRMAXSHEAR)
+        nShearAngle = SDRMAXSHEAR;
+
+    rGeo.nShearAngle = nShearAngle;
     rGeo.RecalcTan();
-    Point aRU(aPt0);
-    aRU.AdjustX(nWdt );
-    aRU.AdjustY(nHgt );
-    rRect=tools::Rectangle(aPt0,aRU);
+
+    Point aRU(aPoint0);
+    aRU.AdjustX(nWidth);
+    aRU.AdjustY(nHeight);
+
+    return tools::Rectangle(aPoint0, aRU);
 }
 
+} // end svx
 
 void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho)
 {
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index e4ff92bc3bed..4bf65c5e364b 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -1644,7 +1644,7 @@ awt::Point SAL_CALL SvxCustomShape::getPosition()
                 aPol[2]=aPol0[3];
                 aPol[3]=aPol0[2];
                 aPol[4]=aPol0[1];
-                Poly2Rect(aPol,aRectangle,aNewGeo);
+                aRectangle = svx::polygonToRectangle(aPol, aNewGeo);
             }
             if ( bMirroredY )
             {
@@ -1666,7 +1666,7 @@ awt::Point SAL_CALL SvxCustomShape::getPosition()
                 aPol[2]=aPol0[3];
                 aPol[3]=aPol0[2];
                 aPol[4]=aPol0[1];
-                Poly2Rect( aPol, aRectangle, aNewGeo );
+                aRectangle = svx::polygonToRectangle(aPol, aNewGeo);
             }
         }
         Point aPt( aRectangle.TopLeft() );

Reply via email to