diff options
Diffstat (limited to 'basegfx/source/polygon/b2dpolygon.cxx')
-rw-r--r-- | basegfx/source/polygon/b2dpolygon.cxx | 330 |
1 files changed, 133 insertions, 197 deletions
diff --git a/basegfx/source/polygon/b2dpolygon.cxx b/basegfx/source/polygon/b2dpolygon.cxx index 3c85a2666d25..cf7309d20dd3 100644 --- a/basegfx/source/polygon/b2dpolygon.cxx +++ b/basegfx/source/polygon/b2dpolygon.cxx @@ -17,7 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <osl/diagnose.h> +#include <sal/config.h> + #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/point/b2dpoint.hxx> #include <basegfx/vector/b2dvector.hxx> @@ -28,34 +29,13 @@ #include <memory> #include <vector> -namespace { - -struct CoordinateData2D : public basegfx::B2DPoint +namespace { -public: - CoordinateData2D() {} - - explicit CoordinateData2D(const basegfx::B2DPoint& rData) - : B2DPoint(rData) - {} - - CoordinateData2D& operator=(const basegfx::B2DPoint& rData) - { - B2DPoint::operator=(rData); - return *this; - } - - void transform(const basegfx::B2DHomMatrix& rMatrix) - { - *this *= rMatrix; - } -}; class CoordinateDataArray2D { - typedef std::vector< CoordinateData2D > CoordinateData2DVector; - - CoordinateData2DVector maVector; +private: + std::vector<basegfx::B2DPoint> maVector; public: explicit CoordinateDataArray2D(sal_uInt32 nCount) @@ -80,11 +60,13 @@ public: const basegfx::B2DPoint& getCoordinate(sal_uInt32 nIndex) const { + assert(nIndex < maVector.size()); return maVector[nIndex]; } void setCoordinate(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue) { + assert(nIndex < maVector.size()); maVector[nIndex] = rValue; } @@ -93,59 +75,50 @@ public: maVector.reserve(nCount); } - void append(const CoordinateData2D& rValue) + void append(const basegfx::B2DPoint& rValue) { maVector.push_back(rValue); } - void insert(sal_uInt32 nIndex, const CoordinateData2D& rValue, sal_uInt32 nCount) + void insert(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue, sal_uInt32 nCount) { - if(nCount) - { - // add nCount copies of rValue - CoordinateData2DVector::iterator aIndex(maVector.begin()); - aIndex += nIndex; - maVector.insert(aIndex, nCount, rValue); - } + assert(nCount > 0); + assert(nIndex <= maVector.size()); + // add nCount copies of rValue + maVector.insert(maVector.begin() + nIndex, nCount, rValue); } void insert(sal_uInt32 nIndex, const CoordinateDataArray2D& rSource) { - const sal_uInt32 nCount(rSource.maVector.size()); - - if(nCount) - { - // insert data - CoordinateData2DVector::iterator aIndex(maVector.begin()); - aIndex += nIndex; - CoordinateData2DVector::const_iterator aStart(rSource.maVector.begin()); - CoordinateData2DVector::const_iterator aEnd(rSource.maVector.end()); - maVector.insert(aIndex, aStart, aEnd); - } + assert(rSource.maVector.size() > 0); + assert(nIndex <= maVector.size()); + // insert data + auto aIndex = maVector.begin(); + aIndex += nIndex; + auto aStart = rSource.maVector.cbegin(); + auto aEnd = rSource.maVector.cend(); + maVector.insert(aIndex, aStart, aEnd); } void remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - if(nCount) - { - // remove point data - CoordinateData2DVector::iterator aStart(maVector.begin()); - aStart += nIndex; - const CoordinateData2DVector::iterator aEnd(aStart + nCount); - maVector.erase(aStart, aEnd); - } + assert(nCount > 0); + assert(nIndex + nCount <= maVector.size()); + // remove point data + const auto aStart = maVector.begin() + nIndex; + const auto aEnd = aStart + nCount; + maVector.erase(aStart, aEnd); } void flip(bool bIsClosed) { - if(maVector.size() <= 1) - return; + assert(maVector.size() > 1); // to keep the same point at index 0, just flip all points except the // first one when closed const sal_uInt32 nHalfSize(bIsClosed ? (maVector.size() - 1) >> 1 : maVector.size() >> 1); - CoordinateData2DVector::iterator aStart(bIsClosed ? maVector.begin() + 1 : maVector.begin()); - CoordinateData2DVector::iterator aEnd(maVector.end() - 1); + auto aStart = bIsClosed ? maVector.begin() + 1 : maVector.begin(); + auto aEnd = maVector.end() - 1; for(sal_uInt32 a(0); a < nHalfSize; a++) { @@ -188,9 +161,9 @@ public: void transform(const basegfx::B2DHomMatrix& rMatrix) { - for (auto & elem : maVector) + for (auto& point : maVector) { - elem.transform(rMatrix); + point *= rMatrix; } } }; @@ -252,10 +225,9 @@ public: ControlVectorArray2D(const ControlVectorArray2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount) : mnUsedVectors(0) { - ControlVectorPair2DVector::const_iterator aStart(rOriginal.maVector.begin()); - aStart += nIndex; - ControlVectorPair2DVector::const_iterator aEnd(aStart); - aEnd += nCount; + assert(nIndex + nCount <= rOriginal.maVector.size()); + auto aStart(rOriginal.maVector.begin() + nIndex); + auto aEnd(aStart + nCount); maVector.reserve(nCount); for(; aStart != aEnd; ++aStart) @@ -282,6 +254,7 @@ public: const basegfx::B2DVector& getPrevVector(sal_uInt32 nIndex) const { + assert(nIndex < maVector.size()); return maVector[nIndex].getPrevVector(); } @@ -314,6 +287,7 @@ public: const basegfx::B2DVector& getNextVector(sal_uInt32 nIndex) const { + assert(nIndex < maVector.size()); return maVector[nIndex].getNextVector(); } @@ -357,13 +331,11 @@ public: void insert(sal_uInt32 nIndex, const ControlVectorPair2D& rValue, sal_uInt32 nCount) { - if(!nCount) - return; + assert(nCount > 0); + assert(nIndex <= maVector.size()); // add nCount copies of rValue - ControlVectorPair2DVector::iterator aIndex(maVector.begin()); - aIndex += nIndex; - maVector.insert(aIndex, nCount, rValue); + maVector.insert(maVector.begin() + nIndex, nCount, rValue); if(!rValue.getPrevVector().equalZero()) mnUsedVectors += nCount; @@ -374,14 +346,11 @@ public: void insert(sal_uInt32 nIndex, const ControlVectorArray2D& rSource) { - const sal_uInt32 nCount(rSource.maVector.size()); - - if(!nCount) - return; + assert(rSource.maVector.size() > 0); + assert(nIndex <= maVector.size()); // insert data - ControlVectorPair2DVector::iterator aIndex(maVector.begin()); - aIndex += nIndex; + ControlVectorPair2DVector::iterator aIndex(maVector.begin() + nIndex); ControlVectorPair2DVector::const_iterator aStart(rSource.maVector.begin()); ControlVectorPair2DVector::const_iterator aEnd(rSource.maVector.end()); maVector.insert(aIndex, aStart, aEnd); @@ -398,8 +367,8 @@ public: void remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - if(!nCount) - return; + assert(nCount > 0); + assert(nIndex + nCount <= maVector.size()); const ControlVectorPair2DVector::iterator aDeleteStart(maVector.begin() + nIndex); const ControlVectorPair2DVector::iterator aDeleteEnd(aDeleteStart + nCount); @@ -420,8 +389,7 @@ public: void flip(bool bIsClosed) { - if(maVector.size() <= 1) - return; + assert(maVector.size() > 1); // to keep the same point at index 0, just flip all points except the // first one when closed @@ -460,7 +428,7 @@ class ImplBufferedData : public basegfx::SystemDependentDataHolder { private: // Possibility to hold the last subdivision - std::optional< basegfx::B2DPolygon > mpDefaultSubdivision; + mutable std::optional< basegfx::B2DPolygon > mpDefaultSubdivision; // Possibility to hold the last B2DRange calculation mutable std::optional< basegfx::B2DRange > moB2DRange; @@ -474,7 +442,7 @@ public: { if(!mpDefaultSubdivision) { - const_cast< ImplBufferedData* >(this)->mpDefaultSubdivision = basegfx::utils::adaptiveSubdivideByAngle(rSource); + mpDefaultSubdivision = basegfx::utils::adaptiveSubdivideByAngle(rSource); } return *mpDefaultSubdivision; @@ -563,7 +531,9 @@ private: std::optional< ControlVectorArray2D > moControlVector; // buffered data for e.g. default subdivision and range - std::unique_ptr< ImplBufferedData > mpBufferedData; + // we do not want to 'modify' the ImplB2DPolygon, + // but add buffered data that is valid for all referencing instances + mutable std::unique_ptr<ImplBufferedData> mpBufferedData; // flag which decides if this polygon is opened or closed bool mbIsClosed; @@ -578,7 +548,7 @@ public: if(!mpBufferedData) { - const_cast< ImplB2DPolygon* >(this)->mpBufferedData.reset(new ImplBufferedData); + mpBufferedData.reset(new ImplBufferedData); } return mpBufferedData->getDefaultAdaptiveSubdivision(rSource); @@ -588,7 +558,7 @@ public: { if(!mpBufferedData) { - const_cast< ImplB2DPolygon* >(this)->mpBufferedData.reset(new ImplBufferedData); + mpBufferedData.reset(new ImplBufferedData); } return mpBufferedData->getB2DRange(rSource); @@ -713,7 +683,7 @@ public: void append(const basegfx::B2DPoint& rPoint) { mpBufferedData.reset(); // TODO: is this needed? - const CoordinateData2D aCoordinate(rPoint); + const auto aCoordinate = rPoint; maPoints.append(aCoordinate); if(moControlVector) @@ -725,20 +695,23 @@ public: void insert(sal_uInt32 nIndex, const basegfx::B2DPoint& rPoint, sal_uInt32 nCount) { - if(nCount) - { - mpBufferedData.reset(); - CoordinateData2D aCoordinate(rPoint); - maPoints.insert(nIndex, aCoordinate, nCount); + assert(nCount > 0); + mpBufferedData.reset(); + auto aCoordinate = rPoint; + maPoints.insert(nIndex, aCoordinate, nCount); - if(moControlVector) - { - ControlVectorPair2D aVectorPair; - moControlVector->insert(nIndex, aVectorPair, nCount); - } + if(moControlVector) + { + ControlVectorPair2D aVectorPair; + moControlVector->insert(nIndex, aVectorPair, nCount); } } + void append(const basegfx::B2DPoint& rPoint, sal_uInt32 nCount) + { + insert(count(), rPoint, nCount); + } + const basegfx::B2DVector& getPrevControlVector(sal_uInt32 nIndex) const { if(moControlVector) @@ -836,24 +809,19 @@ public: setPrevControlVector(nCount, rPrev); } - void insert(sal_uInt32 nIndex, const ImplB2DPolygon& rSource) + void append(const ImplB2DPolygon& rSource) { - const sal_uInt32 nCount(rSource.maPoints.count()); - - if(!nCount) - return; + assert(rSource.maPoints.count() > 0); + const sal_uInt32 nIndex = count(); mpBufferedData.reset(); - if(rSource.moControlVector && rSource.moControlVector->isUsed() && !moControlVector) - { - moControlVector.emplace(maPoints.count()); - } - maPoints.insert(nIndex, rSource.maPoints); if(rSource.moControlVector) { + if (!moControlVector) + moControlVector.emplace(nIndex); moControlVector->insert(nIndex, *rSource.moControlVector); if(!moControlVector->isUsed()) @@ -862,15 +830,13 @@ public: else if(moControlVector) { ControlVectorPair2D aVectorPair; - moControlVector->insert(nIndex, aVectorPair, nCount); + moControlVector->insert(nIndex, aVectorPair, rSource.count()); } } void remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - if(!nCount) - return; - + assert(nCount > 0); mpBufferedData.reset(); maPoints.remove(nIndex, nCount); @@ -885,8 +851,7 @@ public: void flip() { - if(maPoints.count() <= 1) - return; + assert(maPoints.count() > 1); mpBufferedData.reset(); @@ -1087,7 +1052,7 @@ public: } } - void addOrReplaceSystemDependentData(basegfx::SystemDependentData_SharedPtr& rData) + void addOrReplaceSystemDependentData(basegfx::SystemDependentData_SharedPtr& rData) const { if(!mpBufferedData) { @@ -1110,7 +1075,10 @@ public: namespace basegfx { - B2DPolygon::B2DPolygon() = default; + static o3tl::cow_wrapper<ImplB2DPolygon> DEFAULT; + + B2DPolygon::B2DPolygon() + : mpPolygon(DEFAULT) {} B2DPolygon::B2DPolygon(std::initializer_list<basegfx::B2DPoint> aPoints) { @@ -1127,9 +1095,6 @@ namespace basegfx B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount) : mpPolygon(ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount)) { - // TODO(P2): one extra temporary here (cow_wrapper copies - // given ImplB2DPolygon into its internal impl_t wrapper type) - OSL_ENSURE(nIndex + nCount <= rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)"); } B2DPolygon::~B2DPolygon() = default; @@ -1151,11 +1116,6 @@ namespace basegfx return ((*mpPolygon) == (*rPolygon.mpPolygon)); } - bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const - { - return !(*this == rPolygon); - } - sal_uInt32 B2DPolygon::count() const { return mpPolygon->count(); @@ -1163,16 +1123,12 @@ namespace basegfx B2DPoint const & B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - return mpPolygon->getPoint(nIndex); } void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - - if(std::as_const(mpPolygon)->getPoint(nIndex) != rValue) + if(getB2DPoint(nIndex) != rValue) { mpPolygon->setPoint(nIndex, rValue); } @@ -1185,8 +1141,6 @@ namespace basegfx void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPoint& rPoint, sal_uInt32 nCount) { - OSL_ENSURE(nIndex <= std::as_const(mpPolygon)->count(), "B2DPolygon Insert outside range (!)"); - if(nCount) { mpPolygon->insert(nIndex, rPoint, nCount); @@ -1197,7 +1151,7 @@ namespace basegfx { if(nCount) { - mpPolygon->insert(std::as_const(mpPolygon)->count(), rPoint, nCount); + mpPolygon->append(rPoint, nCount); } } @@ -1206,40 +1160,45 @@ namespace basegfx mpPolygon->append(rPoint); } - B2DPoint B2DPolygon::getPrevControlPoint(sal_uInt32 nIndex) const + const basegfx::B2DVector& B2DPolygon::getPrevControlVector(sal_uInt32 nIndex) const + { + return mpPolygon->getPrevControlVector(nIndex); + } + + const basegfx::B2DVector& B2DPolygon::getNextControlVector(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); + return mpPolygon->getNextControlVector(nIndex); + } - if(mpPolygon->areControlPointsUsed()) + B2DPoint B2DPolygon::getPrevControlPoint(sal_uInt32 nIndex) const + { + if(areControlPointsUsed()) { - return mpPolygon->getPoint(nIndex) + mpPolygon->getPrevControlVector(nIndex); + return getB2DPoint(nIndex) + getPrevControlVector(nIndex); } else { - return mpPolygon->getPoint(nIndex); + return getB2DPoint(nIndex); } } B2DPoint B2DPolygon::getNextControlPoint(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - if(mpPolygon->areControlPointsUsed()) + if(areControlPointsUsed()) { - return mpPolygon->getPoint(nIndex) + mpPolygon->getNextControlVector(nIndex); + return getB2DPoint(nIndex) + getNextControlVector(nIndex); } else { - return mpPolygon->getPoint(nIndex); + return getB2DPoint(nIndex); } } void B2DPolygon::setPrevControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - const basegfx::B2DVector aNewVector(rValue - std::as_const(mpPolygon)->getPoint(nIndex)); + const basegfx::B2DVector aNewVector(rValue - getB2DPoint(nIndex)); - if(std::as_const(mpPolygon)->getPrevControlVector(nIndex) != aNewVector) + if(getPrevControlVector(nIndex) != aNewVector) { mpPolygon->setPrevControlVector(nIndex, aNewVector); } @@ -1247,10 +1206,9 @@ namespace basegfx void B2DPolygon::setNextControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - const basegfx::B2DVector aNewVector(rValue - std::as_const(mpPolygon)->getPoint(nIndex)); + const basegfx::B2DVector aNewVector(rValue - getB2DPoint(nIndex)); - if(std::as_const(mpPolygon)->getNextControlVector(nIndex) != aNewVector) + if(getNextControlVector(nIndex) != aNewVector) { mpPolygon->setNextControlVector(nIndex, aNewVector); } @@ -1258,12 +1216,11 @@ namespace basegfx void B2DPolygon::setControlPoints(sal_uInt32 nIndex, const basegfx::B2DPoint& rPrev, const basegfx::B2DPoint& rNext) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - const B2DPoint aPoint(std::as_const(mpPolygon)->getPoint(nIndex)); + const B2DPoint aPoint(getB2DPoint(nIndex)); const basegfx::B2DVector aNewPrev(rPrev - aPoint); const basegfx::B2DVector aNewNext(rNext - aPoint); - if(std::as_const(mpPolygon)->getPrevControlVector(nIndex) != aNewPrev || std::as_const(mpPolygon)->getNextControlVector(nIndex) != aNewNext) + if(getPrevControlVector(nIndex) != aNewPrev || getNextControlVector(nIndex) != aNewNext) { mpPolygon->setControlVectors(nIndex, aNewPrev, aNewNext); } @@ -1271,9 +1228,7 @@ namespace basegfx void B2DPolygon::resetPrevControlPoint(sal_uInt32 nIndex) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - - if(std::as_const(mpPolygon)->areControlPointsUsed() && !std::as_const(mpPolygon)->getPrevControlVector(nIndex).equalZero()) + if(areControlPointsUsed() && !getPrevControlVector(nIndex).equalZero()) { mpPolygon->setPrevControlVector(nIndex, B2DVector::getEmptyVector()); } @@ -1281,9 +1236,7 @@ namespace basegfx void B2DPolygon::resetNextControlPoint(sal_uInt32 nIndex) { - OSL_ENSURE(nIndex < std::as_const(mpPolygon)->count(), "B2DPolygon access outside range (!)"); - - if(std::as_const(mpPolygon)->areControlPointsUsed() && !std::as_const(mpPolygon)->getNextControlVector(nIndex).equalZero()) + if(areControlPointsUsed() && !getNextControlVector(nIndex).equalZero()) { mpPolygon->setNextControlVector(nIndex, B2DVector::getEmptyVector()); } @@ -1291,7 +1244,7 @@ namespace basegfx void B2DPolygon::resetControlPoints() { - if(std::as_const(mpPolygon)->areControlPointsUsed()) + if(areControlPointsUsed()) { mpPolygon->resetControlVectors(); } @@ -1302,12 +1255,12 @@ namespace basegfx const B2DPoint& rPrevControlPoint, const B2DPoint& rPoint) { - const B2DVector aNewNextVector(std::as_const(mpPolygon)->count() ? B2DVector(rNextControlPoint - std::as_const(mpPolygon)->getPoint(std::as_const(mpPolygon)->count() - 1)) : B2DVector::getEmptyVector()); + const B2DVector aNewNextVector(count() ? B2DVector(rNextControlPoint - getB2DPoint(count() - 1)) : B2DVector::getEmptyVector()); const B2DVector aNewPrevVector(rPrevControlPoint - rPoint); if(aNewNextVector.equalZero() && aNewPrevVector.equalZero()) { - mpPolygon->insert(std::as_const(mpPolygon)->count(), rPoint, 1); + mpPolygon->append(rPoint); } else { @@ -1317,7 +1270,7 @@ namespace basegfx void B2DPolygon::appendQuadraticBezierSegment(const B2DPoint& rControlPoint, const B2DPoint& rPoint) { - if (std::as_const(mpPolygon)->count() == 0) + if (count() == 0) { mpPolygon->append(rPoint); const double nX((rControlPoint.getX() * 2.0 + rPoint.getX()) / 3.0); @@ -1326,7 +1279,7 @@ namespace basegfx } else { - const B2DPoint aPreviousPoint(std::as_const(mpPolygon)->getPoint(std::as_const(mpPolygon)->count() - 1)); + const B2DPoint aPreviousPoint(getB2DPoint(count() - 1)); const double nX1((rControlPoint.getX() * 2.0 + aPreviousPoint.getX()) / 3.0); const double nY1((rControlPoint.getY() * 2.0 + aPreviousPoint.getY()) / 3.0); @@ -1344,26 +1297,20 @@ namespace basegfx bool B2DPolygon::isPrevControlPointUsed(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - return (mpPolygon->areControlPointsUsed() && !mpPolygon->getPrevControlVector(nIndex).equalZero()); + return (areControlPointsUsed() && !getPrevControlVector(nIndex).equalZero()); } bool B2DPolygon::isNextControlPointUsed(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - return (mpPolygon->areControlPointsUsed() && !mpPolygon->getNextControlVector(nIndex).equalZero()); + return (areControlPointsUsed() && !getNextControlVector(nIndex).equalZero()); } B2VectorContinuity B2DPolygon::getContinuityInPoint(sal_uInt32 nIndex) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - - if(mpPolygon->areControlPointsUsed()) + if(areControlPointsUsed()) { - const B2DVector& rPrev(mpPolygon->getPrevControlVector(nIndex)); - const B2DVector& rNext(mpPolygon->getNextControlVector(nIndex)); + const B2DVector& rPrev(getPrevControlVector(nIndex)); + const B2DVector& rNext(getNextControlVector(nIndex)); return getContinuity(rPrev, rNext); } @@ -1375,19 +1322,18 @@ namespace basegfx void B2DPolygon::getBezierSegment(sal_uInt32 nIndex, B2DCubicBezier& rTarget) const { - OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)"); - const bool bNextIndexValidWithoutClose(nIndex + 1 < mpPolygon->count()); + const bool bNextIndexValidWithoutClose(nIndex + 1 < count()); - if(bNextIndexValidWithoutClose || mpPolygon->isClosed()) + if(bNextIndexValidWithoutClose || isClosed()) { const sal_uInt32 nNextIndex(bNextIndexValidWithoutClose ? nIndex + 1 : 0); - rTarget.setStartPoint(mpPolygon->getPoint(nIndex)); - rTarget.setEndPoint(mpPolygon->getPoint(nNextIndex)); + rTarget.setStartPoint(getB2DPoint(nIndex)); + rTarget.setEndPoint(getB2DPoint(nNextIndex)); - if(mpPolygon->areControlPointsUsed()) + if(areControlPointsUsed()) { - rTarget.setControlPointA(rTarget.getStartPoint() + mpPolygon->getNextControlVector(nIndex)); - rTarget.setControlPointB(rTarget.getEndPoint() + mpPolygon->getPrevControlVector(nNextIndex)); + rTarget.setControlPointA(rTarget.getStartPoint() + getNextControlVector(nIndex)); + rTarget.setControlPointB(rTarget.getEndPoint() + getPrevControlVector(nNextIndex)); } else { @@ -1399,7 +1345,7 @@ namespace basegfx else { // no valid edge at all, reset rTarget to current point - const B2DPoint aPoint(mpPolygon->getPoint(nIndex)); + const B2DPoint aPoint(getB2DPoint(nIndex)); rTarget.setStartPoint(aPoint); rTarget.setEndPoint(aPoint); rTarget.setControlPointA(aPoint); @@ -1419,30 +1365,27 @@ namespace basegfx void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount) { - if(!rPoly.count()) - return; + assert(nIndex + nCount <= rPoly.count()); if(!nCount) { - nCount = rPoly.count(); + nCount = rPoly.count() - nIndex; + if (!nCount) + return; } if(nIndex == 0 && nCount == rPoly.count()) { - mpPolygon->insert(std::as_const(mpPolygon)->count(), *rPoly.mpPolygon); + mpPolygon->append(*rPoly.mpPolygon); } else { - OSL_ENSURE(nIndex + nCount <= rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)"); - ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount); - mpPolygon->insert(std::as_const(mpPolygon)->count(), aTempPoly); + mpPolygon->append(ImplB2DPolygon(*rPoly.mpPolygon, nIndex, nCount)); } } void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount) { - OSL_ENSURE(nIndex + nCount <= std::as_const(mpPolygon)->count(), "B2DPolygon Remove outside range (!)"); - if(nCount) { mpPolygon->remove(nIndex, nCount); @@ -1477,7 +1420,7 @@ namespace basegfx bool B2DPolygon::hasDoublePoints() const { - return (mpPolygon->count() > 1 && mpPolygon->hasDoublePoints()); + return (count() > 1 && mpPolygon->hasDoublePoints()); } void B2DPolygon::removeDoublePoints() @@ -1491,7 +1434,7 @@ namespace basegfx void B2DPolygon::transform(const B2DHomMatrix& rMatrix) { - if(std::as_const(mpPolygon)->count() && !rMatrix.isIdentity()) + if(count() && !rMatrix.isIdentity()) { mpPolygon->transform(rMatrix); } @@ -1499,14 +1442,7 @@ namespace basegfx void B2DPolygon::addOrReplaceSystemDependentDataInternal(SystemDependentData_SharedPtr& rData) const { - // Need to get ImplB2DPolygon* from cow_wrapper *without* - // calling make_unique() here - we do not want to - // 'modify' the ImplB2DPolygon, but add buffered data that - // is valid for all referencing instances - const B2DPolygon* pMe(this); - const ImplB2DPolygon* pMyImpl(pMe->mpPolygon.get()); - - const_cast<ImplB2DPolygon*>(pMyImpl)->addOrReplaceSystemDependentData(rData); + mpPolygon->addOrReplaceSystemDependentData(rData); } SystemDependentData_SharedPtr B2DPolygon::getSystemDependantDataInternal(size_t hash_code) const |