diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-12 11:46:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-12 12:11:36 +0100 |
commit | b2247f86e42c05991165834ff5d63731b0da2b3b (patch) | |
tree | 228aa497c115de6cee2e7da625fd38610c368cbc | |
parent | 67c541621b701a6873f4e507ad9cc4119b2985bf (diff) |
improve mergeToSinglePolyPolygon
spotted by llunak.
No need to take param by &&, since mergeToSinglePol does not
actually need to modify it.
Also flatten it a little.
Change-Id: I2f5ade347db756e21ecb0a88c3935805268f5072
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125086
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | basegfx/source/polygon/b2dpolypolygoncutter.cxx | 74 | ||||
-rw-r--r-- | include/basegfx/polygon/b2dpolypolygoncutter.hxx | 2 | ||||
-rw-r--r-- | svgio/source/svgreader/svgclippathnode.cxx | 2 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 4 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 4 |
5 files changed, 41 insertions, 45 deletions
diff --git a/basegfx/source/polygon/b2dpolypolygoncutter.cxx b/basegfx/source/polygon/b2dpolypolygoncutter.cxx index 9d3cd7b450df..ac1e10660607 100644 --- a/basegfx/source/polygon/b2dpolypolygoncutter.cxx +++ b/basegfx/source/polygon/b2dpolypolygoncutter.cxx @@ -1067,81 +1067,77 @@ namespace basegfx::utils } } - B2DPolyPolygon mergeToSinglePolyPolygon(B2DPolyPolygonVector&& rInput) + B2DPolyPolygon mergeToSinglePolyPolygon(const B2DPolyPolygonVector& rInput) { - B2DPolyPolygonVector aInput(std::move(rInput)); + if(rInput.empty()) + return B2DPolyPolygon(); // first step: prepareForPolygonOperation and simple merge of non-overlapping // PolyPolygons for speedup; this is possible for the wanted OR-operation - if(!aInput.empty()) + B2DPolyPolygonVector aResult; + aResult.reserve(rInput.size()); + + for(const basegfx::B2DPolyPolygon & a : rInput) { - B2DPolyPolygonVector aResult; - aResult.reserve(aInput.size()); + const basegfx::B2DPolyPolygon aCandidate(prepareForPolygonOperation(a)); - for(const basegfx::B2DPolyPolygon & a : aInput) + if(!aResult.empty()) { - const basegfx::B2DPolyPolygon aCandidate(prepareForPolygonOperation(a)); + const B2DRange aCandidateRange(aCandidate.getB2DRange()); + bool bCouldMergeSimple(false); - if(!aResult.empty()) + for(auto & b: aResult) { - const B2DRange aCandidateRange(aCandidate.getB2DRange()); - bool bCouldMergeSimple(false); - - for(auto & b: aResult) - { - basegfx::B2DPolyPolygon aTarget(b); - const B2DRange aTargetRange(aTarget.getB2DRange()); - - if(!aCandidateRange.overlaps(aTargetRange)) - { - aTarget.append(aCandidate); - b = aTarget; - bCouldMergeSimple = true; - break; - } - } + basegfx::B2DPolyPolygon aTarget(b); + const B2DRange aTargetRange(aTarget.getB2DRange()); - if(!bCouldMergeSimple) + if(!aCandidateRange.overlaps(aTargetRange)) { - aResult.push_back(aCandidate); + aTarget.append(aCandidate); + b = aTarget; + bCouldMergeSimple = true; + break; } } - else + + if(!bCouldMergeSimple) { aResult.push_back(aCandidate); } } - - aInput = aResult; + else + { + aResult.push_back(aCandidate); + } } // second step: melt pairwise to a single PolyPolygon - while(aInput.size() > 1) + while(aResult.size() > 1) { - B2DPolyPolygonVector aResult; - aResult.reserve((aInput.size() / 2) + 1); + B2DPolyPolygonVector aResult2; + aResult2.reserve((aResult.size() / 2) + 1); - for(size_t a(0); a < aInput.size(); a += 2) + for(size_t a(0); a < aResult.size(); a += 2) { - if(a + 1 < aInput.size()) + if(a + 1 < aResult.size()) { // a pair for processing - aResult.push_back(solvePolygonOperationOr(aInput[a], aInput[a + 1])); + aResult2.push_back(solvePolygonOperationOr(aResult[a], aResult[a + 1])); } else { // last single PolyPolygon; copy to target to not lose it - aResult.push_back(aInput[a]); + aResult2.push_back(aResult[a]); } } - aInput = aResult; + aResult = aResult2; } // third step: get result - if(aInput.size() == 1) + if(aResult.size() == 1) { - return aInput[0]; + return aResult[0]; } return B2DPolyPolygon(); diff --git a/include/basegfx/polygon/b2dpolypolygoncutter.hxx b/include/basegfx/polygon/b2dpolypolygoncutter.hxx index 864d84643281..a5f4ba6626af 100644 --- a/include/basegfx/polygon/b2dpolypolygoncutter.hxx +++ b/include/basegfx/polygon/b2dpolypolygoncutter.hxx @@ -136,7 +136,7 @@ namespace basegfx::utils @return A single tools::PolyPolygon containing the Or-merged result */ - BASEGFX_DLLPUBLIC B2DPolyPolygon mergeToSinglePolyPolygon(B2DPolyPolygonVector&& rInput); + BASEGFX_DLLPUBLIC B2DPolyPolygon mergeToSinglePolyPolygon(const B2DPolyPolygonVector& rInput); } // end of namespace basegfx::utils diff --git a/svgio/source/svgreader/svgclippathnode.cxx b/svgio/source/svgreader/svgclippathnode.cxx index 7f4b4beae8ec..31ac632d33dc 100644 --- a/svgio/source/svgreader/svgclippathnode.cxx +++ b/svgio/source/svgreader/svgclippathnode.cxx @@ -148,7 +148,7 @@ namespace svgio::svgreader if(nSize > 1) { // merge to single clipPolyPolygon - aClipPolyPolygon = basegfx::utils::mergeToSinglePolyPolygon(std::vector(rResult)); + aClipPolyPolygon = basegfx::utils::mergeToSinglePolyPolygon(rResult); } else { diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index e7a0d90b7efc..21ef7cebf5cf 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -304,7 +304,7 @@ namespace svgio::svgreader if(!aTextFillVector.empty()) { - aMergedArea = basegfx::utils::mergeToSinglePolyPolygon(std::move(aTextFillVector)); + aMergedArea = basegfx::utils::mergeToSinglePolyPolygon(aTextFillVector); } } @@ -763,7 +763,7 @@ namespace svgio::svgreader { const basegfx::B2DPolyPolygon aMergedArea( basegfx::utils::mergeToSinglePolyPolygon( - std::vector(rLineFillVector))); + rLineFillVector)); if(aMergedArea.count()) { diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index cc5e309a4d40..1fb1518386d0 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -1075,8 +1075,8 @@ void SkiaSalGraphicsImpl::checkPendingDrawing() { for (basegfx::B2DPolyPolygon& p : polygons) roundPolygonPoints(p); - performDrawPolyPolygon(basegfx::utils::mergeToSinglePolyPolygon(std::move(polygons)), - transparency, true); + performDrawPolyPolygon(basegfx::utils::mergeToSinglePolyPolygon(polygons), transparency, + true); } } |