summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorbuldi <dobrakowskirafal@gmail.com>2023-03-13 23:09:18 +0100
committerHossein <hossein@libreoffice.org>2023-06-13 09:23:54 +0200
commit65a20a85c20ddc87d66445657404a46041bcf6e1 (patch)
tree5bdfd640d55cbbfe851e8e4b1639ad408ea56f3e /basegfx
parentc374628126ad222be48d5d06857b7dc6b879f783 (diff)
tdf#145538 Refactor to use range-based for-loop
Change-Id: I7c75593fef6d3226011a938349850dc485b763c2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148204 Tested-by: Jenkins Reviewed-by: Hossein <hossein@libreoffice.org>
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/polygon/b2dpolygonclipper.cxx16
-rw-r--r--basegfx/source/polygon/b2dpolygoncutandtouch.cxx6
-rw-r--r--basegfx/source/polygon/b2dpolygontriangulator.cxx9
-rw-r--r--basegfx/source/polygon/b2dpolypolygoncutter.cxx46
-rw-r--r--basegfx/source/polygon/b3dpolypolygontools.cxx27
5 files changed, 41 insertions, 63 deletions
diff --git a/basegfx/source/polygon/b2dpolygonclipper.cxx b/basegfx/source/polygon/b2dpolygonclipper.cxx
index e9099b730578..e2f1f060381e 100644
--- a/basegfx/source/polygon/b2dpolygonclipper.cxx
+++ b/basegfx/source/polygon/b2dpolygonclipper.cxx
@@ -162,12 +162,11 @@ namespace basegfx::utils
B2DPolyPolygon clipPolyPolygonOnParallelAxis(const B2DPolyPolygon& rCandidate, bool bParallelToXAxis, bool bAboveAxis, double fValueOnOtherAxis, bool bStroke)
{
- const sal_uInt32 nPolygonCount(rCandidate.count());
B2DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < nPolygonCount; a++)
+ for(const auto& rB2DPolygon : rCandidate )
{
- const B2DPolyPolygon aClippedPolyPolygon(clipPolygonOnParallelAxis(rCandidate.getB2DPolygon(a), bParallelToXAxis, bAboveAxis, fValueOnOtherAxis, bStroke));
+ const B2DPolyPolygon aClippedPolyPolygon(clipPolygonOnParallelAxis(rB2DPolygon, bParallelToXAxis, bAboveAxis, fValueOnOtherAxis, bStroke));
if(aClippedPolyPolygon.count())
{
@@ -284,10 +283,9 @@ namespace basegfx::utils
B2DPolyPolygon clipPolyPolygonOnRange(const B2DPolyPolygon& rCandidate, const B2DRange& rRange, bool bInside, bool bStroke)
{
- const sal_uInt32 nPolygonCount(rCandidate.count());
B2DPolyPolygon aRetval;
- if(!nPolygonCount)
+ if(!rCandidate.count())
{
// source is empty
return aRetval;
@@ -309,9 +307,9 @@ namespace basegfx::utils
if(bInside)
{
- for(sal_uInt32 a(0); a < nPolygonCount; a++)
+ for( const auto& rClippedPoly : rCandidate)
{
- const B2DPolyPolygon aClippedPolyPolygon(clipPolygonOnRange(rCandidate.getB2DPolygon(a), rRange, bInside, bStroke));
+ const B2DPolyPolygon aClippedPolyPolygon(clipPolygonOnRange(rClippedPoly , rRange, bInside, bStroke));
if(aClippedPolyPolygon.count())
{
@@ -345,10 +343,10 @@ namespace basegfx::utils
// line clipping, create line snippets by first adding all cut points and
// then marching along the edges and detecting if they are inside or outside
// the clip polygon
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for(const auto& rPolygon : rCandidate)
{
// add cuts with clip to polygon, including bezier segments
- const B2DPolygon aCandidate(addPointsAtCuts(rCandidate.getB2DPolygon(a), rClip));
+ const B2DPolygon aCandidate(addPointsAtCuts(rPolygon, rClip));
const sal_uInt32 nPointCount(aCandidate.count());
const sal_uInt32 nEdgeCount(aCandidate.isClosed() ? nPointCount : nPointCount - 1);
B2DCubicBezier aEdge;
diff --git a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx
index d5ab5887da61..92a0abce6c77 100644
--- a/basegfx/source/polygon/b2dpolygoncutandtouch.cxx
+++ b/basegfx/source/polygon/b2dpolygoncutandtouch.cxx
@@ -179,14 +179,12 @@ namespace basegfx
// (as in adaptiveSubdivideByCount) it is now possible to calculate back the
// cut positions in the polygon to relative cut positions on the original bezier
// segment.
- const sal_uInt32 nTempPointCount(rPointVector.size());
const sal_uInt32 nEdgeCount(rPolygon.count() ? rPolygon.count() - 1 : 0);
- if(nTempPointCount && nEdgeCount)
+ if(!rPointVector.empty() && nEdgeCount)
{
- for(sal_uInt32 a(0); a < nTempPointCount; a++)
+ for( const auto& rTempPoint : rPointVector )
{
- const temporaryPoint& rTempPoint = rPointVector[a];
const double fCutPosInPolygon(static_cast<double>(rTempPoint.getIndex()) + rTempPoint.getCut());
const double fRelativeCutPos(fCutPosInPolygon / static_cast<double>(nEdgeCount));
rTempPoints.emplace_back(rTempPoint.getPoint(), nInd, fRelativeCutPos);
diff --git a/basegfx/source/polygon/b2dpolygontriangulator.cxx b/basegfx/source/polygon/b2dpolygontriangulator.cxx
index 5fbd3960e585..8742ade70e46 100644
--- a/basegfx/source/polygon/b2dpolygontriangulator.cxx
+++ b/basegfx/source/polygon/b2dpolygontriangulator.cxx
@@ -218,18 +218,17 @@ namespace basegfx
// by Y,X,atan2 when adding nodes
if(rCandidate.count())
{
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for(const auto& rPolygonCandidate : rCandidate)
{
- const B2DPolygon& aPolygonCandidate(rCandidate.getB2DPolygon(a));
- const sal_uInt32 nCount(aPolygonCandidate.count());
+ const sal_uInt32 nCount {rPolygonCandidate.count()};
if(nCount > 2)
{
- B2DPoint aPrevPnt(aPolygonCandidate.getB2DPoint(nCount - 1));
+ B2DPoint aPrevPnt(rPolygonCandidate.getB2DPoint(nCount - 1));
for(sal_uInt32 b(0); b < nCount; b++)
{
- B2DPoint aNextPnt(aPolygonCandidate.getB2DPoint(b));
+ B2DPoint aNextPnt(rPolygonCandidate.getB2DPoint(b));
if( !aPrevPnt.equal(aNextPnt) )
{
diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
index b548939f3eed..42cfed615fe3 100644
--- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx
+++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx
@@ -31,6 +31,7 @@
#include <utility>
#include <vector>
#include <algorithm>
+#include <numeric>
namespace basegfx
{
@@ -441,9 +442,9 @@ namespace basegfx
{
basegfx::B2DPoint* pLast(&maSNV[0].mpPN->maPoint);
- for(a = 1; a < nNodeCount; a++)
+ for(const auto& rSN : maSNV)
{
- basegfx::B2DPoint* pCurrent(&maSNV[a].mpPN->maPoint);
+ basegfx::B2DPoint* pCurrent(&rSN.mpPN->maPoint);
if(pLast->equal(*pCurrent) && (pLast->getX() != pCurrent->getX() || pLast->getY() != pCurrent->getY()))
{
@@ -533,25 +534,13 @@ namespace basegfx
if(!nOriginalCount)
return;
- sal_uInt32 nPointCount(0);
- sal_uInt32 a(0);
-
- // count points
- for(a = 0; a < nOriginalCount; a++)
- {
- const B2DPolygon& aCandidate(aGeometry.getB2DPolygon(a));
- const sal_uInt32 nCandCount(aCandidate.count());
-
- // If it's not a bezier curve, at least three points would be needed to have a
- // topological relevant (not empty) polygon. Since it's not known here if trivial
- // edges (dead ends) will be kept or sorted out, add non-bezier polygons with
- // more than one point.
- // For bezier curves, the minimum for defining an area is also one.
- if(nCandCount)
- {
- nPointCount += nCandCount;
- }
- }
+ // If it's not a bezier curve, at least three points would be needed to have a
+ // topological relevant (not empty) polygon. Since it's not known here if trivial
+ // edges (dead ends) will be kept or sorted out, add non-bezier polygons with
+ // more than one point.
+ // For bezier curves, the minimum for defining an area is also one.
+ sal_uInt32 nPointCount = std::accumulate( aGeometry.begin(), aGeometry.end(), sal_uInt32(0),
+ [](sal_uInt32 a, const basegfx::B2DPolygon& b){return a + b.count();});
if(!nPointCount)
return;
@@ -564,16 +553,15 @@ namespace basegfx
// fill data
sal_uInt32 nInsertIndex(0);
- for(a = 0; a < nOriginalCount; a++)
+ for(const auto& rCandidate : aGeometry )
{
- const B2DPolygon& aCandidate(aGeometry.getB2DPolygon(a));
- const sal_uInt32 nCandCount(aCandidate.count());
+ const sal_uInt32 nCandCount(rCandidate.count());
// use same condition as above, the data vector is
// pre-allocated
if(nCandCount)
{
- impAddPolygon(nInsertIndex, aCandidate);
+ impAddPolygon(nInsertIndex, rCandidate);
nInsertIndex += nCandCount;
}
}
@@ -708,13 +696,11 @@ namespace basegfx::utils
{
B2DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for(const auto& rPolygon : rCandidate)
{
- const B2DPolygon& aCandidate(rCandidate.getB2DPolygon(a));
-
- if(utils::getOrientation(aCandidate) != B2VectorOrientation::Neutral)
+ if(utils::getOrientation(rPolygon) != B2VectorOrientation::Neutral)
{
- aRetval.append(aCandidate);
+ aRetval.append(rPolygon);
}
}
diff --git a/basegfx/source/polygon/b3dpolypolygontools.cxx b/basegfx/source/polygon/b3dpolypolygontools.cxx
index 62ddd3ae771f..ffd8bded4d59 100644
--- a/basegfx/source/polygon/b3dpolypolygontools.cxx
+++ b/basegfx/source/polygon/b3dpolypolygontools.cxx
@@ -37,12 +37,10 @@ namespace basegfx::utils
B3DRange getRange(const B3DPolyPolygon& rCandidate)
{
B3DRange aRetval;
- const sal_uInt32 nPolygonCount(rCandidate.count());
- for(sal_uInt32 a(0); a < nPolygonCount; a++)
+ for(const auto& rPolygon : rCandidate )
{
- const B3DPolygon& aCandidate = rCandidate.getB3DPolygon(a);
- aRetval.expand(getRange(aCandidate));
+ aRetval.expand(getRange(rPolygon));
}
return aRetval;
@@ -389,9 +387,9 @@ namespace basegfx::utils
{
B3DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for( const auto& rB3DPolygon : rCandidate)
{
- aRetval.append(applyDefaultNormalsSphere(rCandidate.getB3DPolygon(a), rCenter));
+ aRetval.append(applyDefaultNormalsSphere(rB3DPolygon, rCenter));
}
return aRetval;
@@ -401,9 +399,9 @@ namespace basegfx::utils
{
B3DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for( const auto& rB3DPolygon : rCandidate )
{
- aRetval.append(invertNormals(rCandidate.getB3DPolygon(a)));
+ aRetval.append(invertNormals(rB3DPolygon));
}
return aRetval;
@@ -413,9 +411,9 @@ namespace basegfx::utils
{
B3DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for( const auto& rB3DPolygon : rCandidate)
{
- aRetval.append(applyDefaultTextureCoordinatesParallel(rCandidate.getB3DPolygon(a), rRange, bChangeX, bChangeY));
+ aRetval.append(applyDefaultTextureCoordinatesParallel(rB3DPolygon, rRange, bChangeX, bChangeY));
}
return aRetval;
@@ -425,9 +423,9 @@ namespace basegfx::utils
{
B3DPolyPolygon aRetval;
- for(sal_uInt32 a(0); a < rCandidate.count(); a++)
+ for( const auto& rB3DPolygon : rCandidate )
{
- aRetval.append(applyDefaultTextureCoordinatesSphere(rCandidate.getB3DPolygon(a), rCenter, bChangeX, bChangeY));
+ aRetval.append(applyDefaultTextureCoordinatesSphere(rB3DPolygon, rCenter, bChangeX, bChangeY));
}
return aRetval;
@@ -445,10 +443,9 @@ namespace basegfx::utils
{
sal_Int32 nInsideCount(0);
- for(sal_uInt32 a(0); a < nPolygonCount; a++)
+ for(const auto& rPolygon : rCandidate )
{
- const B3DPolygon& aPolygon(rCandidate.getB3DPolygon(a));
- const bool bInside(isInside(aPolygon, rPoint, false/*bWithBorder*/));
+ const bool bInside(isInside(rPolygon, rPoint, false/*bWithBorder*/));
if(bInside)
{