diff options
Diffstat (limited to 'basegfx/source/polygon/b2dpolypolygoncutter.cxx')
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygoncutter.cxx | 65 |
1 files changed, 26 insertions, 39 deletions
diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx index ac1e10660607..4ad6eb5b219d 100644 --- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx +++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx @@ -28,8 +28,10 @@ #include <basegfx/polygon/b2dpolypolygontools.hxx> #include <basegfx/curve/b2dcubicbezier.hxx> #include <sal/log.hxx> +#include <utility> #include <vector> #include <algorithm> +#include <numeric> namespace basegfx { @@ -144,16 +146,16 @@ namespace basegfx if(rVecA.cross(rVecB) > 0.0) { // b is left turn seen from a, test if Test is left of both and so inside (left is seen as inside) - const bool bBoolA(fTools::moreOrEqual(rVecA.cross(rTest), 0.0)); - const bool bBoolB(fTools::lessOrEqual(rVecB.cross(rTest), 0.0)); + const bool bBoolA(rVecA.cross(rTest) >= 0.0); + const bool bBoolB(rVecB.cross(rTest) <= 0.0); return (bBoolA && bBoolB); } else { // b is right turn seen from a, test if Test is right of both and so outside (left is seen as inside) - const bool bBoolA(fTools::lessOrEqual(rVecA.cross(rTest), 0.0)); - const bool bBoolB(fTools::moreOrEqual(rVecB.cross(rTest), 0.0)); + const bool bBoolA(rVecA.cross(rTest) <= 0.0); + const bool bBoolB(rVecB.cross(rTest) >= 0.0); return (!(bBoolA && bBoolB)); } @@ -440,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())) { @@ -513,8 +515,8 @@ namespace basegfx impSolve(); } - explicit solver(const B2DPolyPolygon& rOriginal) - : maOriginal(rOriginal), + explicit solver(B2DPolyPolygon aOriginal, size_t* pPointLimit = nullptr) + : maOriginal(std::move(aOriginal)), mbIsCurve(false), mbChanged(false) { @@ -523,7 +525,7 @@ namespace basegfx if(!nOriginalCount) return; - B2DPolyPolygon aGeometry(utils::addPointsAtCutsAndTouches(maOriginal)); + B2DPolyPolygon aGeometry(utils::addPointsAtCutsAndTouches(maOriginal, pPointLimit)); aGeometry.removeDoublePoints(); aGeometry = utils::simplifyCurveSegments(aGeometry); mbIsCurve = aGeometry.areControlPointsUsed(); @@ -532,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; @@ -563,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; } } @@ -684,11 +673,11 @@ namespace basegfx namespace basegfx::utils { - B2DPolyPolygon solveCrossovers(const B2DPolyPolygon& rCandidate) + B2DPolyPolygon solveCrossovers(const B2DPolyPolygon& rCandidate, size_t* pPointLimit) { if(rCandidate.count() > 0) { - solver aSolver(rCandidate); + solver aSolver(rCandidate, pPointLimit); return aSolver.getB2DPolyPolygon(); } else @@ -707,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); } } |