diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-02-09 21:16:55 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-03-04 09:45:39 +0000 |
commit | fa8a60c76117cdd0f4290fb5afbe7f5c1463d801 (patch) | |
tree | e4996b641685a42c3620797d57fef9fcb3f3f26e | |
parent | bb4a052a768d5936e0e241b15d3c08a56284eeb4 (diff) |
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
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148211
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | include/svx/svdtrans.hxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdoashp.cxx | 4 | ||||
-rw-r--r-- | svx/source/svdraw/svdotxtr.cxx | 6 | ||||
-rw-r--r-- | svx/source/svdraw/svdtrans.cxx | 73 | ||||
-rw-r--r-- | svx/source/unodraw/unoshap2.cxx | 4 |
5 files changed, 56 insertions, 37 deletions
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 5c9f28f5115c..0834e6f3040d 100644 --- a/svx/source/svdraw/svdotxtr.cxx +++ b/svx/source/svdraw/svdotxtr.cxx @@ -153,7 +153,7 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract aPol[4] = aPol0[1]; } tools::Rectangle aRectangle(getRectangle()); - Poly2Rect(aPol, aRectangle, maGeo); + aRectangle = svx::polygonToRectangle(aPol, maGeo); setRectangle(aRectangle); } @@ -224,7 +224,7 @@ void SdrTextObj::NbcShear(const Point& rRef, Degree100 /*nAngle*/, double tn, bo ShearPoint(aPol[i],rRef,tn,bVShear); } auto aRectangle = getRectangle(); - Poly2Rect(aPol, aRectangle, maGeo); + aRectangle = svx::polygonToRectangle(aPol, maGeo); setRectangle(aRectangle); ImpJustifyRect(maRectangle); @@ -261,7 +261,7 @@ void SdrTextObj::NbcMirror(const Point& rRef1, const Point& rRef2) aPol[3]=aPol0[2]; aPol[4]=aPol0[1]; tools::Rectangle aRectangle = getRectangle(); - 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() ); |