LCOV - code coverage report
Current view: top level - basegfx/source/polygon - b2dpolygon.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 569 643 88.5 %
Date: 2014-04-11 Functions: 116 127 91.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/diagnose.h>
      21             : #include <basegfx/polygon/b2dpolygon.hxx>
      22             : #include <basegfx/point/b2dpoint.hxx>
      23             : #include <basegfx/vector/b2dvector.hxx>
      24             : #include <basegfx/matrix/b2dhommatrix.hxx>
      25             : #include <basegfx/curve/b2dcubicbezier.hxx>
      26             : #include <rtl/instance.hxx>
      27             : #include <basegfx/polygon/b2dpolygontools.hxx>
      28             : #include <boost/scoped_ptr.hpp>
      29             : #include <vector>
      30             : #include <algorithm>
      31             : 
      32             : 
      33             : 
      34    56074092 : struct CoordinateData2D : public basegfx::B2DPoint
      35             : {
      36             : public:
      37           0 :     CoordinateData2D() {}
      38             : 
      39     9185397 :     explicit CoordinateData2D(const basegfx::B2DPoint& rData)
      40     9185397 :     :   B2DPoint(rData)
      41     9185397 :     {}
      42             : 
      43     7847496 :     CoordinateData2D& operator=(const basegfx::B2DPoint& rData)
      44             :     {
      45     7847496 :         B2DPoint::operator=(rData);
      46     7847496 :         return *this;
      47             :     }
      48             : 
      49     2868888 :     void transform(const basegfx::B2DHomMatrix& rMatrix)
      50             :     {
      51     2868888 :         *this *= rMatrix;
      52     2868888 :     }
      53             : };
      54             : 
      55             : 
      56             : 
      57     3656675 : class CoordinateDataArray2D
      58             : {
      59             :     typedef ::std::vector< CoordinateData2D > CoordinateData2DVector;
      60             : 
      61             :     CoordinateData2DVector                          maVector;
      62             : 
      63             : public:
      64          93 :     explicit CoordinateDataArray2D(sal_uInt32 nCount)
      65          93 :     :   maVector(nCount)
      66             :     {
      67          93 :     }
      68             : 
      69     3678498 :     explicit CoordinateDataArray2D(const CoordinateDataArray2D& rOriginal)
      70     3678498 :     :   maVector(rOriginal.maVector)
      71             :     {
      72     3678498 :     }
      73             : 
      74           0 :     CoordinateDataArray2D(const CoordinateDataArray2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
      75           0 :     :   maVector(rOriginal.maVector.begin() + nIndex, rOriginal.maVector.begin() + (nIndex + nCount))
      76             :     {
      77           0 :     }
      78             : 
      79    13026796 :     sal_uInt32 count() const
      80             :     {
      81    13026796 :         return maVector.size();
      82             :     }
      83             : 
      84       28751 :     bool operator==(const CoordinateDataArray2D& rCandidate) const
      85             :     {
      86       28751 :         return (maVector == rCandidate.maVector);
      87             :     }
      88             : 
      89   116070372 :     const basegfx::B2DPoint& getCoordinate(sal_uInt32 nIndex) const
      90             :     {
      91   116070372 :         return maVector[nIndex];
      92             :     }
      93             : 
      94     7847496 :     void setCoordinate(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue)
      95             :     {
      96     7847496 :         maVector[nIndex] = rValue;
      97     7847496 :     }
      98             : 
      99       58532 :     void reserve(sal_uInt32 nCount)
     100             :     {
     101       58532 :         maVector.reserve(nCount);
     102       58532 :     }
     103             : 
     104     7182169 :     void append(const CoordinateData2D& rValue)
     105             :     {
     106     7182169 :         maVector.push_back(rValue);
     107     7182169 :     }
     108             : 
     109     2003228 :     void insert(sal_uInt32 nIndex, const CoordinateData2D& rValue, sal_uInt32 nCount)
     110             :     {
     111     2003228 :         if(nCount)
     112             :         {
     113             :             // add nCount copies of rValue
     114     2003228 :             CoordinateData2DVector::iterator aIndex(maVector.begin());
     115     2003228 :             aIndex += nIndex;
     116     2003228 :             maVector.insert(aIndex, nCount, rValue);
     117             :         }
     118     2003228 :     }
     119             : 
     120         633 :     void insert(sal_uInt32 nIndex, const CoordinateDataArray2D& rSource)
     121             :     {
     122         633 :         const sal_uInt32 nCount(rSource.maVector.size());
     123             : 
     124         633 :         if(nCount)
     125             :         {
     126             :             // insert data
     127         633 :             CoordinateData2DVector::iterator aIndex(maVector.begin());
     128         633 :             aIndex += nIndex;
     129         633 :             CoordinateData2DVector::const_iterator aStart(rSource.maVector.begin());
     130         633 :             CoordinateData2DVector::const_iterator aEnd(rSource.maVector.end());
     131         633 :             maVector.insert(aIndex, aStart, aEnd);
     132             :         }
     133         633 :     }
     134             : 
     135       26451 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     136             :     {
     137       26451 :         if(nCount)
     138             :         {
     139             :             // remove point data
     140       26451 :             CoordinateData2DVector::iterator aStart(maVector.begin());
     141       26451 :             aStart += nIndex;
     142       26451 :             const CoordinateData2DVector::iterator aEnd(aStart + nCount);
     143       26451 :             maVector.erase(aStart, aEnd);
     144             :         }
     145       26451 :     }
     146             : 
     147         624 :     void flip(bool bIsClosed)
     148             :     {
     149         624 :         if(maVector.size() > 1)
     150             :         {
     151             :             // to keep the same point at index 0, just flip all points except the
     152             :             // first one when closed
     153         624 :             const sal_uInt32 nHalfSize(bIsClosed ? (maVector.size() - 1) >> 1 : maVector.size() >> 1);
     154         624 :             CoordinateData2DVector::iterator aStart(bIsClosed ? maVector.begin() + 1 : maVector.begin());
     155         624 :             CoordinateData2DVector::iterator aEnd(maVector.end() - 1);
     156             : 
     157        1655 :             for(sal_uInt32 a(0); a < nHalfSize; a++)
     158             :             {
     159        1031 :                 ::std::swap(*aStart, *aEnd);
     160        1031 :                 ++aStart;
     161        1031 :                 --aEnd;
     162             :             }
     163             :         }
     164         624 :     }
     165             : 
     166         536 :     void removeDoublePointsAtBeginEnd()
     167             :     {
     168             :         // remove from end as long as there are at least two points
     169             :         // and begin/end are equal
     170        1646 :         while((maVector.size() > 1) && (maVector[0] == maVector[maVector.size() - 1]))
     171             :         {
     172         574 :             maVector.pop_back();
     173             :         }
     174         536 :     }
     175             : 
     176         867 :     void removeDoublePointsWholeTrack()
     177             :     {
     178         867 :         sal_uInt32 nIndex(0);
     179             : 
     180             :         // test as long as there are at least two points and as long as the index
     181             :         // is smaller or equal second last point
     182       10805 :         while((maVector.size() > 1) && (nIndex <= maVector.size() - 2))
     183             :         {
     184        9071 :             if(maVector[nIndex] == maVector[nIndex + 1])
     185             :             {
     186             :                 // if next is same as index, delete next
     187         935 :                 maVector.erase(maVector.begin() + (nIndex + 1));
     188             :             }
     189             :             else
     190             :             {
     191             :                 // if different, step forward
     192        8136 :                 nIndex++;
     193             :             }
     194             :         }
     195         867 :     }
     196             : 
     197      678154 :     void transform(const basegfx::B2DHomMatrix& rMatrix)
     198             :     {
     199      678154 :         CoordinateData2DVector::iterator aStart(maVector.begin());
     200      678154 :         CoordinateData2DVector::iterator aEnd(maVector.end());
     201             : 
     202     3547042 :         for(; aStart != aEnd; ++aStart)
     203             :         {
     204     2868888 :             aStart->transform(rMatrix);
     205             :         }
     206      678154 :     }
     207             : };
     208             : 
     209             : 
     210             : 
     211     1277947 : class ControlVectorPair2D
     212             : {
     213             :     basegfx::B2DVector                          maPrevVector;
     214             :     basegfx::B2DVector                          maNextVector;
     215             : 
     216             : public:
     217      129480 :     explicit ControlVectorPair2D() {}
     218             : 
     219     2055414 :     const basegfx::B2DVector& getPrevVector() const
     220             :     {
     221     2055414 :         return maPrevVector;
     222             :     }
     223             : 
     224      265770 :     void setPrevVector(const basegfx::B2DVector& rValue)
     225             :     {
     226      265770 :         if(rValue != maPrevVector)
     227      241470 :             maPrevVector = rValue;
     228      265770 :     }
     229             : 
     230     2019496 :     const basegfx::B2DVector& getNextVector() const
     231             :     {
     232     2019496 :         return maNextVector;
     233             :     }
     234             : 
     235      260488 :     void setNextVector(const basegfx::B2DVector& rValue)
     236             :     {
     237      260488 :         if(rValue != maNextVector)
     238      236177 :             maNextVector = rValue;
     239      260488 :     }
     240             : 
     241        2417 :     bool operator==(const ControlVectorPair2D& rData) const
     242             :     {
     243        2417 :         return (maPrevVector == rData.getPrevVector() && maNextVector == rData.getNextVector());
     244             :     }
     245             : 
     246           0 :     void flip()
     247             :     {
     248           0 :         ::std::swap(maPrevVector, maNextVector);
     249           0 :     }
     250             : };
     251             : 
     252             : 
     253             : 
     254       72665 : class ControlVectorArray2D
     255             : {
     256             :     typedef ::std::vector< ControlVectorPair2D > ControlVectorPair2DVector;
     257             : 
     258             :     ControlVectorPair2DVector                           maVector;
     259             :     sal_uInt32                                          mnUsedVectors;
     260             : 
     261             : public:
     262       13995 :     explicit ControlVectorArray2D(sal_uInt32 nCount)
     263             :     :   maVector(nCount),
     264       13995 :         mnUsedVectors(0)
     265       13995 :     {}
     266             : 
     267           0 :     ControlVectorArray2D(const ControlVectorArray2D& rOriginal, sal_uInt32 nIndex, sal_uInt32 nCount)
     268             :     :   maVector(),
     269           0 :         mnUsedVectors(0)
     270             :     {
     271           0 :         ControlVectorPair2DVector::const_iterator aStart(rOriginal.maVector.begin());
     272           0 :         aStart += nIndex;
     273           0 :         ControlVectorPair2DVector::const_iterator aEnd(aStart);
     274           0 :         aEnd += nCount;
     275           0 :         maVector.reserve(nCount);
     276             : 
     277           0 :         for(; aStart != aEnd; ++aStart)
     278             :         {
     279           0 :             if(!aStart->getPrevVector().equalZero())
     280           0 :                 mnUsedVectors++;
     281             : 
     282           0 :             if(!aStart->getNextVector().equalZero())
     283           0 :                 mnUsedVectors++;
     284             : 
     285           0 :             maVector.push_back(*aStart);
     286             :         }
     287           0 :     }
     288             : 
     289         797 :     bool operator==(const ControlVectorArray2D& rCandidate) const
     290             :     {
     291         797 :         return (maVector == rCandidate.maVector);
     292             :     }
     293             : 
     294     2510147 :     bool isUsed() const
     295             :     {
     296     2510147 :         return (0 != mnUsedVectors);
     297             :     }
     298             : 
     299     1668359 :     const basegfx::B2DVector& getPrevVector(sal_uInt32 nIndex) const
     300             :     {
     301     1668359 :         return maVector[nIndex].getPrevVector();
     302             :     }
     303             : 
     304      267561 :     void setPrevVector(sal_uInt32 nIndex, const basegfx::B2DVector& rValue)
     305             :     {
     306      267561 :         bool bWasUsed(mnUsedVectors && !maVector[nIndex].getPrevVector().equalZero());
     307      267561 :         bool bIsUsed(!rValue.equalZero());
     308             : 
     309      267561 :         if(bWasUsed)
     310             :         {
     311      194516 :             if(bIsUsed)
     312             :             {
     313      194516 :                 maVector[nIndex].setPrevVector(rValue);
     314             :             }
     315             :             else
     316             :             {
     317           0 :                 maVector[nIndex].setPrevVector(basegfx::B2DVector::getEmptyVector());
     318           0 :                 mnUsedVectors--;
     319             :             }
     320             :         }
     321             :         else
     322             :         {
     323       73045 :             if(bIsUsed)
     324             :             {
     325       71254 :                 maVector[nIndex].setPrevVector(rValue);
     326       71254 :                 mnUsedVectors++;
     327             :             }
     328             :         }
     329      267561 :     }
     330             : 
     331     1649807 :     const basegfx::B2DVector& getNextVector(sal_uInt32 nIndex) const
     332             :     {
     333     1649807 :         return maVector[nIndex].getNextVector();
     334             :     }
     335             : 
     336      261897 :     void setNextVector(sal_uInt32 nIndex, const basegfx::B2DVector& rValue)
     337             :     {
     338      261897 :         bool bWasUsed(mnUsedVectors && !maVector[nIndex].getNextVector().equalZero());
     339      261897 :         bool bIsUsed(!rValue.equalZero());
     340             : 
     341      261897 :         if(bWasUsed)
     342             :         {
     343      194172 :             if(bIsUsed)
     344             :             {
     345      194172 :                 maVector[nIndex].setNextVector(rValue);
     346             :             }
     347             :             else
     348             :             {
     349           0 :                 maVector[nIndex].setNextVector(basegfx::B2DVector::getEmptyVector());
     350           0 :                 mnUsedVectors--;
     351             :             }
     352             :         }
     353             :         else
     354             :         {
     355       67725 :             if(bIsUsed)
     356             :             {
     357       66316 :                 maVector[nIndex].setNextVector(rValue);
     358       66316 :                 mnUsedVectors++;
     359             :             }
     360             :         }
     361      261897 :     }
     362             : 
     363       42248 :     void append(const ControlVectorPair2D& rValue)
     364             :     {
     365       42248 :         maVector.push_back(rValue);
     366             : 
     367       42248 :         if(!rValue.getPrevVector().equalZero())
     368           0 :             mnUsedVectors += 1;
     369             : 
     370       42248 :         if(!rValue.getNextVector().equalZero())
     371           0 :             mnUsedVectors += 1;
     372       42248 :     }
     373             : 
     374       65537 :     void insert(sal_uInt32 nIndex, const ControlVectorPair2D& rValue, sal_uInt32 nCount)
     375             :     {
     376       65537 :         if(nCount)
     377             :         {
     378             :             // add nCount copies of rValue
     379       65537 :             ControlVectorPair2DVector::iterator aIndex(maVector.begin());
     380       65537 :             aIndex += nIndex;
     381       65537 :             maVector.insert(aIndex, nCount, rValue);
     382             : 
     383       65537 :             if(!rValue.getPrevVector().equalZero())
     384           0 :                 mnUsedVectors += nCount;
     385             : 
     386       65537 :             if(!rValue.getNextVector().equalZero())
     387           0 :                 mnUsedVectors += nCount;
     388             :         }
     389       65537 :     }
     390             : 
     391          42 :     void insert(sal_uInt32 nIndex, const ControlVectorArray2D& rSource)
     392             :     {
     393          42 :         const sal_uInt32 nCount(rSource.maVector.size());
     394             : 
     395          42 :         if(nCount)
     396             :         {
     397             :             // insert data
     398          42 :             ControlVectorPair2DVector::iterator aIndex(maVector.begin());
     399          42 :             aIndex += nIndex;
     400          42 :             ControlVectorPair2DVector::const_iterator aStart(rSource.maVector.begin());
     401          42 :             ControlVectorPair2DVector::const_iterator aEnd(rSource.maVector.end());
     402          42 :             maVector.insert(aIndex, aStart, aEnd);
     403             : 
     404         244 :             for(; aStart != aEnd; ++aStart)
     405             :             {
     406         202 :                 if(!aStart->getPrevVector().equalZero())
     407         160 :                     mnUsedVectors++;
     408             : 
     409         202 :                 if(!aStart->getNextVector().equalZero())
     410         160 :                     mnUsedVectors++;
     411             :             }
     412             :         }
     413          42 :     }
     414             : 
     415       10213 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     416             :     {
     417       10213 :         if(nCount)
     418             :         {
     419       10213 :             const ControlVectorPair2DVector::iterator aDeleteStart(maVector.begin() + nIndex);
     420       10213 :             const ControlVectorPair2DVector::iterator aDeleteEnd(aDeleteStart + nCount);
     421       10213 :             ControlVectorPair2DVector::const_iterator aStart(aDeleteStart);
     422             : 
     423       20444 :             for(; mnUsedVectors && aStart != aDeleteEnd; ++aStart)
     424             :             {
     425       10231 :                 if(!aStart->getPrevVector().equalZero())
     426        4572 :                     mnUsedVectors--;
     427             : 
     428       10231 :                 if(mnUsedVectors && !aStart->getNextVector().equalZero())
     429           2 :                     mnUsedVectors--;
     430             :             }
     431             : 
     432             :             // remove point data
     433       10213 :             maVector.erase(aDeleteStart, aDeleteEnd);
     434             :         }
     435       10213 :     }
     436             : 
     437           0 :     void flip(bool bIsClosed)
     438             :     {
     439           0 :         if(maVector.size() > 1)
     440             :         {
     441             :             // to keep the same point at index 0, just flip all points except the
     442             :             // first one when closed
     443           0 :             const sal_uInt32 nHalfSize(bIsClosed ? (maVector.size() - 1) >> 1 : maVector.size() >> 1);
     444           0 :             ControlVectorPair2DVector::iterator aStart(bIsClosed ? maVector.begin() + 1 : maVector.begin());
     445           0 :             ControlVectorPair2DVector::iterator aEnd(maVector.end() - 1);
     446             : 
     447           0 :             for(sal_uInt32 a(0); a < nHalfSize; a++)
     448             :             {
     449             :                 // swap Prev and Next
     450           0 :                 aStart->flip();
     451           0 :                 aEnd->flip();
     452             : 
     453             :                 // swap entries
     454           0 :                 ::std::swap(*aStart, *aEnd);
     455             : 
     456           0 :                 ++aStart;
     457           0 :                 --aEnd;
     458             :             }
     459             : 
     460           0 :             if(aStart == aEnd)
     461             :             {
     462             :                 // swap Prev and Next at middle element (if exists)
     463           0 :                 aStart->flip();
     464             :             }
     465             : 
     466           0 :             if(bIsClosed)
     467             :             {
     468             :                 // swap Prev and Next at start element
     469           0 :                 maVector.begin()->flip();
     470             :             }
     471             :         }
     472           0 :     }
     473             : };
     474             : 
     475             : 
     476             : 
     477     2893395 : class ImplBufferedData
     478             : {
     479             : private:
     480             :     // Possibility to hold the last subdivision
     481             :     boost::scoped_ptr< basegfx::B2DPolygon >        mpDefaultSubdivision;
     482             : 
     483             :     // Possibility to hold the last B2DRange calculation
     484             :     boost::scoped_ptr< basegfx::B2DRange >          mpB2DRange;
     485             : 
     486             : public:
     487     2907485 :     ImplBufferedData()
     488             :     :   mpDefaultSubdivision(),
     489     2907485 :         mpB2DRange()
     490     2907485 :     {}
     491             : 
     492        5373 :     const basegfx::B2DPolygon& getDefaultAdaptiveSubdivision(const basegfx::B2DPolygon& rSource) const
     493             :     {
     494        5373 :         if(!mpDefaultSubdivision)
     495             :         {
     496        2571 :             const_cast< ImplBufferedData* >(this)->mpDefaultSubdivision.reset(new basegfx::B2DPolygon(basegfx::tools::adaptiveSubdivideByCount(rSource, 9)));
     497             :         }
     498             : 
     499        5373 :         return *mpDefaultSubdivision;
     500             :     }
     501             : 
     502     3369973 :     const basegfx::B2DRange& getB2DRange(const basegfx::B2DPolygon& rSource) const
     503             :     {
     504     3369973 :         if(!mpB2DRange)
     505             :         {
     506     2907414 :             basegfx::B2DRange aNewRange;
     507     2907414 :             const sal_uInt32 nPointCount(rSource.count());
     508             : 
     509     2907414 :             if(nPointCount)
     510             :             {
     511    16598000 :                 for(sal_uInt32 a(0); a < nPointCount; a++)
     512             :                 {
     513    13690586 :                     aNewRange.expand(rSource.getB2DPoint(a));
     514             :                 }
     515             : 
     516     2907414 :                 if(rSource.areControlPointsUsed())
     517             :                 {
     518       20906 :                     const sal_uInt32 nEdgeCount(rSource.isClosed() ? nPointCount : nPointCount - 1);
     519             : 
     520       20906 :                     if(nEdgeCount)
     521             :                     {
     522       20906 :                         basegfx::B2DCubicBezier aEdge;
     523       20906 :                         aEdge.setStartPoint(rSource.getB2DPoint(0));
     524             : 
     525      211751 :                         for(sal_uInt32 b(0); b < nEdgeCount; b++)
     526             :                         {
     527      190845 :                             const sal_uInt32 nNextIndex((b + 1) % nPointCount);
     528      190845 :                             aEdge.setControlPointA(rSource.getNextControlPoint(b));
     529      190845 :                             aEdge.setControlPointB(rSource.getPrevControlPoint(nNextIndex));
     530      190845 :                             aEdge.setEndPoint(rSource.getB2DPoint(nNextIndex));
     531             : 
     532      190845 :                             if(aEdge.isBezier())
     533             :                             {
     534      105079 :                                 const basegfx::B2DRange aBezierRangeWithControlPoints(aEdge.getRange());
     535             : 
     536      105079 :                                 if(!aNewRange.isInside(aBezierRangeWithControlPoints))
     537             :                                 {
     538             :                                     // the range with control points of the current edge is not completely
     539             :                                     // inside the current range without control points. Expand current range by
     540             :                                     // subdividing the bezier segment.
     541             :                                     // Ideal here is a subdivision at the extreme values, so use
     542             :                                     // getAllExtremumPositions to get all extremas in one run
     543       19052 :                                     ::std::vector< double > aExtremas;
     544             : 
     545       19052 :                                     aExtremas.reserve(4);
     546       19052 :                                     aEdge.getAllExtremumPositions(aExtremas);
     547             : 
     548       19052 :                                     const sal_uInt32 nExtremaCount(aExtremas.size());
     549             : 
     550       37761 :                                     for(sal_uInt32 c(0); c < nExtremaCount; c++)
     551             :                                     {
     552       18709 :                                         aNewRange.expand(aEdge.interpolatePoint(aExtremas[c]));
     553       19052 :                                     }
     554             :                                 }
     555             :                             }
     556             : 
     557             :                             // prepare next edge
     558      190845 :                             aEdge.setStartPoint(aEdge.getEndPoint());
     559       20906 :                         }
     560             :                     }
     561             :                 }
     562             :             }
     563             : 
     564     2907414 :             const_cast< ImplBufferedData* >(this)->mpB2DRange.reset(new basegfx::B2DRange(aNewRange));
     565             :         }
     566             : 
     567     3369973 :         return *mpB2DRange;
     568             :     }
     569             : };
     570             : 
     571             : 
     572             : 
     573     3656675 : class ImplB2DPolygon
     574             : {
     575             : private:
     576             :     // The point vector. This vector exists always and defines the
     577             :     // count of members.
     578             :     CoordinateDataArray2D                           maPoints;
     579             : 
     580             :     // The control point vectors. This vectors are created on demand
     581             :     // and may be zero.
     582             :     boost::scoped_ptr< ControlVectorArray2D >       mpControlVector;
     583             : 
     584             :     // buffered data for e.g. default subdivision and range
     585             :     boost::scoped_ptr< ImplBufferedData >           mpBufferedData;
     586             : 
     587             :     // flag which decides if this polygon is opened or closed
     588             :     bool                                            mbIsClosed;
     589             : 
     590             : public:
     591        5387 :     const basegfx::B2DPolygon& getDefaultAdaptiveSubdivision(const basegfx::B2DPolygon& rSource) const
     592             :     {
     593        5387 :         if(!mpControlVector || !mpControlVector->isUsed())
     594             :         {
     595          14 :             return rSource;
     596             :         }
     597             : 
     598        5373 :         if(!mpBufferedData)
     599             :         {
     600         545 :             const_cast< ImplB2DPolygon* >(this)->mpBufferedData.reset(new ImplBufferedData);
     601             :         }
     602             : 
     603        5373 :         return mpBufferedData->getDefaultAdaptiveSubdivision(rSource);
     604             :     }
     605             : 
     606     3369973 :     const basegfx::B2DRange& getB2DRange(const basegfx::B2DPolygon& rSource) const
     607             :     {
     608     3369973 :         if(!mpBufferedData)
     609             :         {
     610     2906940 :             const_cast< ImplB2DPolygon* >(this)->mpBufferedData.reset(new ImplBufferedData);
     611             :         }
     612             : 
     613     3369973 :         return mpBufferedData->getB2DRange(rSource);
     614             :     }
     615             : 
     616          93 :     ImplB2DPolygon()
     617             :     :   maPoints(0),
     618             :         mpControlVector(),
     619             :         mpBufferedData(),
     620          93 :         mbIsClosed(false)
     621          93 :     {}
     622             : 
     623     3678498 :     ImplB2DPolygon(const ImplB2DPolygon& rToBeCopied)
     624             :     :   maPoints(rToBeCopied.maPoints),
     625             :         mpControlVector(),
     626             :         mpBufferedData(),
     627     3678498 :         mbIsClosed(rToBeCopied.mbIsClosed)
     628             :     {
     629             :         // complete initialization using copy
     630     3678498 :         if(rToBeCopied.mpControlVector && rToBeCopied.mpControlVector->isUsed())
     631             :         {
     632       29401 :             mpControlVector.reset( new ControlVectorArray2D(*rToBeCopied.mpControlVector) );
     633             :         }
     634     3678498 :     }
     635             : 
     636           0 :     ImplB2DPolygon(const ImplB2DPolygon& rToBeCopied, sal_uInt32 nIndex, sal_uInt32 nCount)
     637             :     :   maPoints(rToBeCopied.maPoints, nIndex, nCount),
     638             :         mpControlVector(),
     639             :         mpBufferedData(),
     640           0 :         mbIsClosed(rToBeCopied.mbIsClosed)
     641             :     {
     642             :         // complete initialization using partly copy
     643           0 :         if(rToBeCopied.mpControlVector && rToBeCopied.mpControlVector->isUsed())
     644             :         {
     645           0 :             mpControlVector.reset( new ControlVectorArray2D(*rToBeCopied.mpControlVector, nIndex, nCount) );
     646             : 
     647           0 :             if(!mpControlVector->isUsed())
     648           0 :                 mpControlVector.reset();
     649             :         }
     650           0 :     }
     651             : 
     652             :     ImplB2DPolygon& operator=( const ImplB2DPolygon& ) SAL_DELETED_FUNCTION;
     653             : 
     654    12461326 :     sal_uInt32 count() const
     655             :     {
     656    12461326 :         return maPoints.count();
     657             :     }
     658             : 
     659     3756313 :     bool isClosed() const
     660             :     {
     661     3756313 :         return mbIsClosed;
     662             :     }
     663             : 
     664     2715339 :     void setClosed(bool bNew)
     665             :     {
     666     2715339 :         if(bNew != mbIsClosed)
     667             :         {
     668     2715339 :             mpBufferedData.reset();
     669     2715339 :             mbIsClosed = bNew;
     670             :         }
     671     2715339 :     }
     672             : 
     673       29803 :     bool operator==(const ImplB2DPolygon& rCandidate) const
     674             :     {
     675       29803 :         if(mbIsClosed == rCandidate.mbIsClosed)
     676             :         {
     677       28751 :             if(maPoints == rCandidate.maPoints)
     678             :             {
     679       21890 :                 bool bControlVectorsAreEqual(true);
     680             : 
     681       21890 :                 if(mpControlVector)
     682             :                 {
     683         797 :                     if(rCandidate.mpControlVector)
     684             :                     {
     685         797 :                         bControlVectorsAreEqual = ((*mpControlVector) == (*rCandidate.mpControlVector));
     686             :                     }
     687             :                     else
     688             :                     {
     689             :                         // candidate has no control vector, so it's assumed all unused.
     690           0 :                         bControlVectorsAreEqual = !mpControlVector->isUsed();
     691             :                     }
     692             :                 }
     693             :                 else
     694             :                 {
     695       21093 :                     if(rCandidate.mpControlVector)
     696             :                     {
     697             :                         // we have no control vector, so it's assumed all unused.
     698          28 :                         bControlVectorsAreEqual = !rCandidate.mpControlVector->isUsed();
     699             :                     }
     700             :                 }
     701             : 
     702       21890 :                 if(bControlVectorsAreEqual)
     703             :                 {
     704       21862 :                     return true;
     705             :                 }
     706             :             }
     707             :         }
     708             : 
     709        7941 :         return false;
     710             :     }
     711             : 
     712   115575271 :     const basegfx::B2DPoint& getPoint(sal_uInt32 nIndex) const
     713             :     {
     714   115575271 :         return maPoints.getCoordinate(nIndex);
     715             :     }
     716             : 
     717     7559867 :     void setPoint(sal_uInt32 nIndex, const basegfx::B2DPoint& rValue)
     718             :     {
     719     7559867 :         mpBufferedData.reset();
     720     7559867 :         maPoints.setCoordinate(nIndex, rValue);
     721     7559867 :     }
     722             : 
     723       58532 :     void reserve(sal_uInt32 nCount)
     724             :     {
     725       58532 :         maPoints.reserve(nCount);
     726       58532 :     }
     727             : 
     728     7182169 :     void append(const basegfx::B2DPoint& rPoint)
     729             :     {
     730     7182169 :         mpBufferedData.reset(); // TODO: is this needed?
     731     7182169 :         const CoordinateData2D aCoordinate(rPoint);
     732     7182169 :         maPoints.append(aCoordinate);
     733             : 
     734     7182169 :         if(mpControlVector)
     735             :         {
     736       42248 :             const ControlVectorPair2D aVectorPair;
     737       42248 :             mpControlVector->append(aVectorPair);
     738     7182169 :         }
     739     7182169 :     }
     740             : 
     741     2003228 :     void insert(sal_uInt32 nIndex, const basegfx::B2DPoint& rPoint, sal_uInt32 nCount)
     742             :     {
     743     2003228 :         if(nCount)
     744             :         {
     745     2003228 :             mpBufferedData.reset();
     746     2003228 :             CoordinateData2D aCoordinate(rPoint);
     747     2003228 :             maPoints.insert(nIndex, aCoordinate, nCount);
     748             : 
     749     2003228 :             if(mpControlVector)
     750             :             {
     751       65533 :                 ControlVectorPair2D aVectorPair;
     752       65533 :                 mpControlVector->insert(nIndex, aVectorPair, nCount);
     753     2003228 :             }
     754             :         }
     755     2003228 :     }
     756             : 
     757     1367850 :     const basegfx::B2DVector& getPrevControlVector(sal_uInt32 nIndex) const
     758             :     {
     759     1367850 :         if(mpControlVector)
     760             :         {
     761     1367443 :             return mpControlVector->getPrevVector(nIndex);
     762             :         }
     763             :         else
     764             :         {
     765         407 :             return basegfx::B2DVector::getEmptyVector();
     766             :         }
     767             :     }
     768             : 
     769       72348 :     void setPrevControlVector(sal_uInt32 nIndex, const basegfx::B2DVector& rValue)
     770             :     {
     771       72348 :         if(!mpControlVector)
     772             :         {
     773        1142 :             if(!rValue.equalZero())
     774             :             {
     775        1141 :                 mpBufferedData.reset();
     776        1141 :                 mpControlVector.reset( new ControlVectorArray2D(maPoints.count()) );
     777        1141 :                 mpControlVector->setPrevVector(nIndex, rValue);
     778             :             }
     779             :         }
     780             :         else
     781             :         {
     782       71206 :             mpBufferedData.reset();
     783       71206 :             mpControlVector->setPrevVector(nIndex, rValue);
     784             : 
     785       71206 :             if(!mpControlVector->isUsed())
     786           0 :                 mpControlVector.reset();
     787             :         }
     788       72348 :     }
     789             : 
     790     1355173 :     const basegfx::B2DVector& getNextControlVector(sal_uInt32 nIndex) const
     791             :     {
     792     1355173 :         if(mpControlVector)
     793             :         {
     794     1355016 :             return mpControlVector->getNextVector(nIndex);
     795             :         }
     796             :         else
     797             :         {
     798         157 :             return basegfx::B2DVector::getEmptyVector();
     799             :         }
     800             :     }
     801             : 
     802       69599 :     void setNextControlVector(sal_uInt32 nIndex, const basegfx::B2DVector& rValue)
     803             :     {
     804       69599 :         if(!mpControlVector)
     805             :         {
     806       13577 :             if(!rValue.equalZero())
     807             :             {
     808       12843 :                 mpBufferedData.reset();
     809       12843 :                 mpControlVector.reset( new ControlVectorArray2D(maPoints.count()) );
     810       12843 :                 mpControlVector->setNextVector(nIndex, rValue);
     811             :             }
     812             :         }
     813             :         else
     814             :         {
     815       56022 :             mpBufferedData.reset();
     816       56022 :             mpControlVector->setNextVector(nIndex, rValue);
     817             : 
     818       56022 :             if(!mpControlVector->isUsed())
     819           0 :                 mpControlVector.reset();
     820             :         }
     821       69599 :     }
     822             : 
     823    10001970 :     bool areControlPointsUsed() const
     824             :     {
     825    10001970 :         return (mpControlVector && mpControlVector->isUsed());
     826             :     }
     827             : 
     828           1 :     void resetControlVectors()
     829             :     {
     830           1 :         mpBufferedData.reset();
     831           1 :         mpControlVector.reset();
     832           1 :     }
     833             : 
     834           1 :     void setControlVectors(sal_uInt32 nIndex, const basegfx::B2DVector& rPrev, const basegfx::B2DVector& rNext)
     835             :     {
     836           1 :         setPrevControlVector(nIndex, rPrev);
     837           1 :         setNextControlVector(nIndex, rNext);
     838           1 :     }
     839             : 
     840       66030 :     void appendBezierSegment(const basegfx::B2DVector& rNext, const basegfx::B2DVector& rPrev, const basegfx::B2DPoint& rPoint)
     841             :     {
     842       66030 :         mpBufferedData.reset();
     843       66030 :         const sal_uInt32 nCount(maPoints.count());
     844             : 
     845       66030 :         if(nCount)
     846             :         {
     847       66029 :             setNextControlVector(nCount - 1, rNext);
     848             :         }
     849             : 
     850       66030 :         insert(nCount, rPoint, 1);
     851       66030 :         setPrevControlVector(nCount, rPrev);
     852       66030 :     }
     853             : 
     854         633 :     void insert(sal_uInt32 nIndex, const ImplB2DPolygon& rSource)
     855             :     {
     856         633 :         const sal_uInt32 nCount(rSource.maPoints.count());
     857             : 
     858         633 :         if(nCount)
     859             :         {
     860         633 :             mpBufferedData.reset();
     861             : 
     862         633 :             if(rSource.mpControlVector && rSource.mpControlVector->isUsed() && !mpControlVector)
     863             :             {
     864          11 :                 mpControlVector.reset( new ControlVectorArray2D(maPoints.count()) );
     865             :             }
     866             : 
     867         633 :             maPoints.insert(nIndex, rSource.maPoints);
     868             : 
     869         633 :             if(rSource.mpControlVector)
     870             :             {
     871          42 :                 mpControlVector->insert(nIndex, *rSource.mpControlVector);
     872             : 
     873          42 :                 if(!mpControlVector->isUsed())
     874           0 :                     mpControlVector.reset();
     875             :             }
     876         591 :             else if(mpControlVector)
     877             :             {
     878           4 :                 ControlVectorPair2D aVectorPair;
     879           4 :                 mpControlVector->insert(nIndex, aVectorPair, nCount);
     880             :             }
     881             :         }
     882         633 :     }
     883             : 
     884       26451 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     885             :     {
     886       26451 :         if(nCount)
     887             :         {
     888       26451 :             mpBufferedData.reset();
     889       26451 :             maPoints.remove(nIndex, nCount);
     890             : 
     891       26451 :             if(mpControlVector)
     892             :             {
     893       10213 :                 mpControlVector->remove(nIndex, nCount);
     894             : 
     895       10213 :                 if(!mpControlVector->isUsed())
     896           0 :                     mpControlVector.reset();
     897             :             }
     898             :         }
     899       26451 :     }
     900             : 
     901         624 :     void flip()
     902             :     {
     903         624 :         if(maPoints.count() > 1)
     904             :         {
     905         624 :             mpBufferedData.reset();
     906             : 
     907             :             // flip points
     908         624 :             maPoints.flip(mbIsClosed);
     909             : 
     910         624 :             if(mpControlVector)
     911             :             {
     912             :                 // flip control vector
     913           0 :                 mpControlVector->flip(mbIsClosed);
     914             :             }
     915             :         }
     916         624 :     }
     917             : 
     918       26639 :     bool hasDoublePoints() const
     919             :     {
     920       26639 :         if(mbIsClosed)
     921             :         {
     922             :             // check for same start and end point
     923       15978 :             const sal_uInt32 nIndex(maPoints.count() - 1);
     924             : 
     925       15978 :             if(maPoints.getCoordinate(0) == maPoints.getCoordinate(nIndex))
     926             :             {
     927        3182 :                 if(mpControlVector)
     928             :                 {
     929        2661 :                     if(mpControlVector->getNextVector(nIndex).equalZero() && mpControlVector->getPrevVector(0).equalZero())
     930             :                     {
     931        2661 :                         return true;
     932             :                     }
     933             :                 }
     934             :                 else
     935             :                 {
     936         521 :                     return true;
     937             :                 }
     938             :             }
     939             :         }
     940             : 
     941             :         // test for range
     942       81671 :         for(sal_uInt32 a(0); a < maPoints.count() - 1; a++)
     943             :         {
     944       58850 :             if(maPoints.getCoordinate(a) == maPoints.getCoordinate(a + 1))
     945             :             {
     946         640 :                 if(mpControlVector)
     947             :                 {
     948         203 :                     if(mpControlVector->getNextVector(a).equalZero() && mpControlVector->getPrevVector(a + 1).equalZero())
     949             :                     {
     950         199 :                         return true;
     951             :                     }
     952             :                 }
     953             :                 else
     954             :                 {
     955         437 :                     return true;
     956             :                 }
     957             :             }
     958             :         }
     959             : 
     960       22821 :         return false;
     961             :     }
     962             : 
     963        3286 :     void removeDoublePointsAtBeginEnd()
     964             :     {
     965             :         // Only remove DoublePoints at Begin and End when poly is closed
     966        3286 :         if(mbIsClosed)
     967             :         {
     968        2791 :             mpBufferedData.reset();
     969             : 
     970        2791 :             if(mpControlVector)
     971             :             {
     972             :                 bool bRemove;
     973             : 
     974        5277 :                 do
     975             :                 {
     976        5277 :                     bRemove = false;
     977             : 
     978        5277 :                     if(maPoints.count() > 1)
     979             :                     {
     980        5277 :                         const sal_uInt32 nIndex(maPoints.count() - 1);
     981             : 
     982        5277 :                         if(maPoints.getCoordinate(0) == maPoints.getCoordinate(nIndex))
     983             :                         {
     984        3024 :                             if(mpControlVector)
     985             :                             {
     986        3024 :                                 if(mpControlVector->getNextVector(nIndex).equalZero() && mpControlVector->getPrevVector(0).equalZero())
     987             :                                 {
     988        3022 :                                     bRemove = true;
     989             :                                 }
     990             :                             }
     991             :                             else
     992             :                             {
     993           0 :                                 bRemove = true;
     994             :                             }
     995             :                         }
     996             :                     }
     997             : 
     998        5277 :                     if(bRemove)
     999             :                     {
    1000        3022 :                         const sal_uInt32 nIndex(maPoints.count() - 1);
    1001             : 
    1002        3022 :                         if(mpControlVector && !mpControlVector->getPrevVector(nIndex).equalZero())
    1003             :                         {
    1004        1304 :                             mpControlVector->setPrevVector(0, mpControlVector->getPrevVector(nIndex));
    1005             :                         }
    1006             : 
    1007        3022 :                         remove(nIndex, 1);
    1008             :                     }
    1009             :                 }
    1010             :                 while(bRemove);
    1011             :             }
    1012             :             else
    1013             :             {
    1014         536 :                 maPoints.removeDoublePointsAtBeginEnd();
    1015             :             }
    1016             :         }
    1017        3286 :     }
    1018             : 
    1019        3286 :     void removeDoublePointsWholeTrack()
    1020             :     {
    1021        3286 :         mpBufferedData.reset();
    1022             : 
    1023        3286 :         if(mpControlVector)
    1024             :         {
    1025        2419 :             sal_uInt32 nIndex(0);
    1026             : 
    1027             :             // test as long as there are at least two points and as long as the index
    1028             :             // is smaller or equal second last point
    1029       28469 :             while((maPoints.count() > 1) && (nIndex <= maPoints.count() - 2))
    1030             :             {
    1031       23631 :                 bool bRemove(maPoints.getCoordinate(nIndex) == maPoints.getCoordinate(nIndex + 1));
    1032             : 
    1033       23631 :                 if(bRemove)
    1034             :                 {
    1035        1274 :                     if(mpControlVector)
    1036             :                     {
    1037        1274 :                         if(!mpControlVector->getNextVector(nIndex).equalZero() || !mpControlVector->getPrevVector(nIndex + 1).equalZero())
    1038             :                         {
    1039           2 :                             bRemove = false;
    1040             :                         }
    1041             :                     }
    1042             :                 }
    1043             : 
    1044       23631 :                 if(bRemove)
    1045             :                 {
    1046        1272 :                     if(mpControlVector && !mpControlVector->getPrevVector(nIndex).equalZero())
    1047             :                     {
    1048         535 :                         mpControlVector->setPrevVector(nIndex + 1, mpControlVector->getPrevVector(nIndex));
    1049             :                     }
    1050             : 
    1051             :                     // if next is same as index and the control vectors are unused, delete index
    1052        1272 :                     remove(nIndex, 1);
    1053             :                 }
    1054             :                 else
    1055             :                 {
    1056             :                     // if different, step forward
    1057       22359 :                     nIndex++;
    1058             :                 }
    1059             :             }
    1060             :         }
    1061             :         else
    1062             :         {
    1063         867 :             maPoints.removeDoublePointsWholeTrack();
    1064             :         }
    1065        3286 :     }
    1066             : 
    1067      711388 :     void transform(const basegfx::B2DHomMatrix& rMatrix)
    1068             :     {
    1069      711388 :         mpBufferedData.reset();
    1070             : 
    1071      711388 :         if(mpControlVector)
    1072             :         {
    1073      320863 :             for(sal_uInt32 a(0); a < maPoints.count(); a++)
    1074             :             {
    1075      287629 :                 basegfx::B2DPoint aCandidate = maPoints.getCoordinate(a);
    1076             : 
    1077      287629 :                 if(mpControlVector->isUsed())
    1078             :                 {
    1079      287629 :                     const basegfx::B2DVector& rPrevVector(mpControlVector->getPrevVector(a));
    1080      287629 :                     const basegfx::B2DVector& rNextVector(mpControlVector->getNextVector(a));
    1081             : 
    1082      287629 :                     if(!rPrevVector.equalZero())
    1083             :                     {
    1084      193375 :                         basegfx::B2DVector aPrevVector(rMatrix * rPrevVector);
    1085      193375 :                         mpControlVector->setPrevVector(a, aPrevVector);
    1086             :                     }
    1087             : 
    1088      287629 :                     if(!rNextVector.equalZero())
    1089             :                     {
    1090      193032 :                         basegfx::B2DVector aNextVector(rMatrix * rNextVector);
    1091      193032 :                         mpControlVector->setNextVector(a, aNextVector);
    1092             :                     }
    1093             :                 }
    1094             : 
    1095      287629 :                 aCandidate *= rMatrix;
    1096      287629 :                 maPoints.setCoordinate(a, aCandidate);
    1097      287629 :             }
    1098             : 
    1099       33234 :             if(!mpControlVector->isUsed())
    1100           0 :                 mpControlVector.reset();
    1101             :         }
    1102             :         else
    1103             :         {
    1104      678154 :             maPoints.transform(rMatrix);
    1105             :         }
    1106      711388 :     }
    1107             : };
    1108             : 
    1109             : 
    1110             : 
    1111             : namespace basegfx
    1112             : {
    1113             :     namespace
    1114             :     {
    1115             :         struct DefaultPolygon: public rtl::Static<B2DPolygon::ImplType, DefaultPolygon> {};
    1116             :     }
    1117             : 
    1118     3030176 :     B2DPolygon::B2DPolygon()
    1119     3030176 :     :   mpPolygon(DefaultPolygon::get())
    1120     3030176 :     {}
    1121             : 
    1122    13013913 :     B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon)
    1123    13013913 :     :   mpPolygon(rPolygon.mpPolygon)
    1124    13013913 :     {}
    1125             : 
    1126           0 :     B2DPolygon::B2DPolygon(const B2DPolygon& rPolygon, sal_uInt32 nIndex, sal_uInt32 nCount)
    1127           0 :     :   mpPolygon(ImplB2DPolygon(*rPolygon.mpPolygon, nIndex, nCount))
    1128             :     {
    1129             :         // TODO(P2): one extra temporary here (cow_wrapper copies
    1130             :         // given ImplB2DPolygon into its internal impl_t wrapper type)
    1131             :         OSL_ENSURE(nIndex + nCount <= rPolygon.mpPolygon->count(), "B2DPolygon constructor outside range (!)");
    1132           0 :     }
    1133             : 
    1134    16020198 :     B2DPolygon::~B2DPolygon()
    1135             :     {
    1136    16020198 :     }
    1137             : 
    1138       66631 :     B2DPolygon& B2DPolygon::operator=(const B2DPolygon& rPolygon)
    1139             :     {
    1140       66631 :         mpPolygon = rPolygon.mpPolygon;
    1141       66631 :         return *this;
    1142             :     }
    1143             : 
    1144          30 :     void B2DPolygon::makeUnique()
    1145             :     {
    1146          30 :         mpPolygon.make_unique();
    1147          30 :     }
    1148             : 
    1149       31154 :     bool B2DPolygon::operator==(const B2DPolygon& rPolygon) const
    1150             :     {
    1151       31154 :         if(mpPolygon.same_object(rPolygon.mpPolygon))
    1152        1351 :             return true;
    1153             : 
    1154       29803 :         return ((*mpPolygon) == (*rPolygon.mpPolygon));
    1155             :     }
    1156             : 
    1157        4526 :     bool B2DPolygon::operator!=(const B2DPolygon& rPolygon) const
    1158             :     {
    1159        4526 :         return !(*this == rPolygon);
    1160             :     }
    1161             : 
    1162     8870342 :     sal_uInt32 B2DPolygon::count() const
    1163             :     {
    1164     8870342 :         return mpPolygon->count();
    1165             :     }
    1166             : 
    1167   104932388 :     B2DPoint B2DPolygon::getB2DPoint(sal_uInt32 nIndex) const
    1168             :     {
    1169             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1170             : 
    1171   104932388 :         return mpPolygon->getPoint(nIndex);
    1172             :     }
    1173             : 
    1174     7927662 :     void B2DPolygon::setB2DPoint(sal_uInt32 nIndex, const B2DPoint& rValue)
    1175             :     {
    1176             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1177             : 
    1178     7927662 :         if(mpPolygon->getPoint(nIndex) != rValue)
    1179             :         {
    1180     7559867 :             mpPolygon->setPoint(nIndex, rValue);
    1181             :         }
    1182     7927662 :     }
    1183             : 
    1184       58532 :     void B2DPolygon::reserve(sal_uInt32 nCount)
    1185             :     {
    1186       58532 :         mpPolygon->reserve(nCount);
    1187       58532 :     }
    1188             : 
    1189         176 :     void B2DPolygon::insert(sal_uInt32 nIndex, const B2DPoint& rPoint, sal_uInt32 nCount)
    1190             :     {
    1191             :         OSL_ENSURE(nIndex <= mpPolygon->count(), "B2DPolygon Insert outside range (!)");
    1192             : 
    1193         176 :         if(nCount)
    1194             :         {
    1195         176 :             mpPolygon->insert(nIndex, rPoint, nCount);
    1196             :         }
    1197         176 :     }
    1198             : 
    1199     1936747 :     void B2DPolygon::append(const B2DPoint& rPoint, sal_uInt32 nCount)
    1200             :     {
    1201     1936747 :         if(nCount)
    1202             :         {
    1203     1936747 :             mpPolygon->insert(mpPolygon->count(), rPoint, nCount);
    1204             :         }
    1205     1936747 :     }
    1206             : 
    1207     7182169 :     void B2DPolygon::append(const B2DPoint& rPoint)
    1208             :     {
    1209     7182169 :         mpPolygon->append(rPoint);
    1210     7182169 :     }
    1211             : 
    1212      550245 :     B2DPoint B2DPolygon::getPrevControlPoint(sal_uInt32 nIndex) const
    1213             :     {
    1214             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1215             : 
    1216      550245 :         if(mpPolygon->areControlPointsUsed())
    1217             :         {
    1218      528793 :             return mpPolygon->getPoint(nIndex) + mpPolygon->getPrevControlVector(nIndex);
    1219             :         }
    1220             :         else
    1221             :         {
    1222       21452 :             return mpPolygon->getPoint(nIndex);
    1223             :         }
    1224             :     }
    1225             : 
    1226      546970 :     B2DPoint B2DPolygon::getNextControlPoint(sal_uInt32 nIndex) const
    1227             :     {
    1228             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1229             : 
    1230      546970 :         if(mpPolygon->areControlPointsUsed())
    1231             :         {
    1232      525530 :             return mpPolygon->getPoint(nIndex) + mpPolygon->getNextControlVector(nIndex);
    1233             :         }
    1234             :         else
    1235             :         {
    1236       21440 :             return mpPolygon->getPoint(nIndex);
    1237             :         }
    1238             :     }
    1239             : 
    1240        7515 :     void B2DPolygon::setPrevControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue)
    1241             :     {
    1242             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1243        7515 :         const basegfx::B2DVector aNewVector(rValue - mpPolygon->getPoint(nIndex));
    1244             : 
    1245        7515 :         if(mpPolygon->getPrevControlVector(nIndex) != aNewVector)
    1246             :         {
    1247        6317 :             mpPolygon->setPrevControlVector(nIndex, aNewVector);
    1248        7515 :         }
    1249        7515 :     }
    1250             : 
    1251        4766 :     void B2DPolygon::setNextControlPoint(sal_uInt32 nIndex, const B2DPoint& rValue)
    1252             :     {
    1253             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1254        4766 :         const basegfx::B2DVector aNewVector(rValue - mpPolygon->getPoint(nIndex));
    1255             : 
    1256        4766 :         if(mpPolygon->getNextControlVector(nIndex) != aNewVector)
    1257             :         {
    1258        3569 :             mpPolygon->setNextControlVector(nIndex, aNewVector);
    1259        4766 :         }
    1260        4766 :     }
    1261             : 
    1262           1 :     void B2DPolygon::setControlPoints(sal_uInt32 nIndex, const basegfx::B2DPoint& rPrev, const basegfx::B2DPoint& rNext)
    1263             :     {
    1264             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1265           1 :         const B2DPoint aPoint(mpPolygon->getPoint(nIndex));
    1266           2 :         const basegfx::B2DVector aNewPrev(rPrev - aPoint);
    1267           2 :         const basegfx::B2DVector aNewNext(rNext - aPoint);
    1268             : 
    1269           1 :         if(mpPolygon->getPrevControlVector(nIndex) != aNewPrev || mpPolygon->getNextControlVector(nIndex) != aNewNext)
    1270             :         {
    1271           1 :             mpPolygon->setControlVectors(nIndex, aNewPrev, aNewNext);
    1272           1 :         }
    1273           1 :     }
    1274             : 
    1275           0 :     void B2DPolygon::resetPrevControlPoint(sal_uInt32 nIndex)
    1276             :     {
    1277             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1278             : 
    1279           0 :         if(mpPolygon->areControlPointsUsed() && !mpPolygon->getPrevControlVector(nIndex).equalZero())
    1280             :         {
    1281           0 :             mpPolygon->setPrevControlVector(nIndex, B2DVector::getEmptyVector());
    1282             :         }
    1283           0 :     }
    1284             : 
    1285           0 :     void B2DPolygon::resetNextControlPoint(sal_uInt32 nIndex)
    1286             :     {
    1287             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1288             : 
    1289           0 :         if(mpPolygon->areControlPointsUsed() && !mpPolygon->getNextControlVector(nIndex).equalZero())
    1290             :         {
    1291           0 :             mpPolygon->setNextControlVector(nIndex, B2DVector::getEmptyVector());
    1292             :         }
    1293           0 :     }
    1294             : 
    1295           1 :     void B2DPolygon::resetControlPoints()
    1296             :     {
    1297           1 :         if(mpPolygon->areControlPointsUsed())
    1298             :         {
    1299           1 :             mpPolygon->resetControlVectors();
    1300             :         }
    1301           1 :     }
    1302             : 
    1303       66305 :     void B2DPolygon::appendBezierSegment(
    1304             :         const B2DPoint& rNextControlPoint,
    1305             :         const B2DPoint& rPrevControlPoint,
    1306             :         const B2DPoint& rPoint)
    1307             :     {
    1308       66305 :         const B2DVector aNewNextVector(mpPolygon->count() ? B2DVector(rNextControlPoint - mpPolygon->getPoint(mpPolygon->count() - 1)) : B2DVector::getEmptyVector());
    1309      132610 :         const B2DVector aNewPrevVector(rPrevControlPoint - rPoint);
    1310             : 
    1311       66305 :         if(aNewNextVector.equalZero() && aNewPrevVector.equalZero())
    1312             :         {
    1313         275 :             mpPolygon->insert(mpPolygon->count(), rPoint, 1);
    1314             :         }
    1315             :         else
    1316             :         {
    1317       66030 :             mpPolygon->appendBezierSegment(aNewNextVector, aNewPrevVector, rPoint);
    1318       66305 :         }
    1319       66305 :     }
    1320             : 
    1321     8007560 :     bool B2DPolygon::areControlPointsUsed() const
    1322             :     {
    1323     8007560 :         return mpPolygon->areControlPointsUsed();
    1324             :     }
    1325             : 
    1326        9320 :     bool B2DPolygon::isPrevControlPointUsed(sal_uInt32 nIndex) const
    1327             :     {
    1328             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1329             : 
    1330        9320 :         return (mpPolygon->areControlPointsUsed() && !mpPolygon->getPrevControlVector(nIndex).equalZero());
    1331             :     }
    1332             : 
    1333        2644 :     bool B2DPolygon::isNextControlPointUsed(sal_uInt32 nIndex) const
    1334             :     {
    1335             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1336             : 
    1337        2644 :         return (mpPolygon->areControlPointsUsed() && !mpPolygon->getNextControlVector(nIndex).equalZero());
    1338             :     }
    1339             : 
    1340      115521 :     B2VectorContinuity B2DPolygon::getContinuityInPoint(sal_uInt32 nIndex) const
    1341             :     {
    1342             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1343             : 
    1344      115521 :         if(mpPolygon->areControlPointsUsed())
    1345             :         {
    1346      115521 :             const B2DVector& rPrev(mpPolygon->getPrevControlVector(nIndex));
    1347      115521 :             const B2DVector& rNext(mpPolygon->getNextControlVector(nIndex));
    1348             : 
    1349      115521 :             return getContinuity(rPrev, rNext);
    1350             :         }
    1351             :         else
    1352             :         {
    1353           0 :             return CONTINUITY_NONE;
    1354             :         }
    1355             :     }
    1356             : 
    1357      769711 :     void B2DPolygon::getBezierSegment(sal_uInt32 nIndex, B2DCubicBezier& rTarget) const
    1358             :     {
    1359             :         OSL_ENSURE(nIndex < mpPolygon->count(), "B2DPolygon access outside range (!)");
    1360      769711 :         const bool bNextIndexValidWithoutClose(nIndex + 1 < mpPolygon->count());
    1361             : 
    1362      769711 :         if(bNextIndexValidWithoutClose || mpPolygon->isClosed())
    1363             :         {
    1364      769709 :             const sal_uInt32 nNextIndex(bNextIndexValidWithoutClose ? nIndex + 1 : 0);
    1365      769709 :             rTarget.setStartPoint(mpPolygon->getPoint(nIndex));
    1366      769709 :             rTarget.setEndPoint(mpPolygon->getPoint(nNextIndex));
    1367             : 
    1368      769709 :             if(mpPolygon->areControlPointsUsed())
    1369             :             {
    1370      706738 :                 rTarget.setControlPointA(rTarget.getStartPoint() + mpPolygon->getNextControlVector(nIndex));
    1371      706738 :                 rTarget.setControlPointB(rTarget.getEndPoint() + mpPolygon->getPrevControlVector(nNextIndex));
    1372             :             }
    1373             :             else
    1374             :             {
    1375             :                 // no bezier, reset control poins at rTarget
    1376       62971 :                 rTarget.setControlPointA(rTarget.getStartPoint());
    1377       62971 :                 rTarget.setControlPointB(rTarget.getEndPoint());
    1378             :             }
    1379             :         }
    1380             :         else
    1381             :         {
    1382             :             // no valid edge at all, reset rTarget to current point
    1383           2 :             const B2DPoint aPoint(mpPolygon->getPoint(nIndex));
    1384           2 :             rTarget.setStartPoint(aPoint);
    1385           2 :             rTarget.setEndPoint(aPoint);
    1386           2 :             rTarget.setControlPointA(aPoint);
    1387           2 :             rTarget.setControlPointB(aPoint);
    1388             :         }
    1389      769711 :     }
    1390             : 
    1391        5387 :     B2DPolygon B2DPolygon::getDefaultAdaptiveSubdivision() const
    1392             :     {
    1393        5387 :         return mpPolygon->getDefaultAdaptiveSubdivision(*this);
    1394             :     }
    1395             : 
    1396     3369973 :     B2DRange B2DPolygon::getB2DRange() const
    1397             :     {
    1398     3369973 :         return mpPolygon->getB2DRange(*this);
    1399             :     }
    1400             : 
    1401         641 :     void B2DPolygon::append(const B2DPolygon& rPoly, sal_uInt32 nIndex, sal_uInt32 nCount)
    1402             :     {
    1403         641 :         if(rPoly.count())
    1404             :         {
    1405         633 :             if(!nCount)
    1406             :             {
    1407         633 :                 nCount = rPoly.count();
    1408             :             }
    1409             : 
    1410         633 :             if(0 == nIndex && nCount == rPoly.count())
    1411             :             {
    1412         633 :                 mpPolygon->insert(mpPolygon->count(), *rPoly.mpPolygon);
    1413             :             }
    1414             :             else
    1415             :             {
    1416             :                 OSL_ENSURE(nIndex + nCount <= rPoly.mpPolygon->count(), "B2DPolygon Append outside range (!)");
    1417           0 :                 ImplB2DPolygon aTempPoly(*rPoly.mpPolygon, nIndex, nCount);
    1418           0 :                 mpPolygon->insert(mpPolygon->count(), aTempPoly);
    1419             :             }
    1420             :         }
    1421         641 :     }
    1422             : 
    1423       22157 :     void B2DPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
    1424             :     {
    1425             :         OSL_ENSURE(nIndex + nCount <= mpPolygon->count(), "B2DPolygon Remove outside range (!)");
    1426             : 
    1427       22157 :         if(nCount)
    1428             :         {
    1429       22157 :             mpPolygon->remove(nIndex, nCount);
    1430             :         }
    1431       22157 :     }
    1432             : 
    1433       99417 :     void B2DPolygon::clear()
    1434             :     {
    1435       99417 :         mpPolygon = DefaultPolygon::get();
    1436       99417 :     }
    1437             : 
    1438     3692542 :     bool B2DPolygon::isClosed() const
    1439             :     {
    1440     3692542 :         return mpPolygon->isClosed();
    1441             :     }
    1442             : 
    1443     2878402 :     void B2DPolygon::setClosed(bool bNew)
    1444             :     {
    1445     2878402 :         if(isClosed() != bNew)
    1446             :         {
    1447     2715339 :             mpPolygon->setClosed(bNew);
    1448             :         }
    1449     2878402 :     }
    1450             : 
    1451         624 :     void B2DPolygon::flip()
    1452             :     {
    1453         624 :         if(count() > 1)
    1454             :         {
    1455         624 :             mpPolygon->flip();
    1456             :         }
    1457         624 :     }
    1458             : 
    1459       27226 :     bool B2DPolygon::hasDoublePoints() const
    1460             :     {
    1461       27226 :         return (mpPolygon->count() > 1 && mpPolygon->hasDoublePoints());
    1462             :     }
    1463             : 
    1464       15212 :     void B2DPolygon::removeDoublePoints()
    1465             :     {
    1466       15212 :         if(hasDoublePoints())
    1467             :         {
    1468        3286 :             mpPolygon->removeDoublePointsAtBeginEnd();
    1469        3286 :             mpPolygon->removeDoublePointsWholeTrack();
    1470             :         }
    1471       15212 :     }
    1472             : 
    1473      723783 :     void B2DPolygon::transform(const B2DHomMatrix& rMatrix)
    1474             :     {
    1475      723783 :         if(mpPolygon->count() && !rMatrix.isIdentity())
    1476             :         {
    1477      711388 :             mpPolygon->transform(rMatrix);
    1478             :         }
    1479      723783 :     }
    1480             : 
    1481             : } // end of namespace basegfx
    1482             : 
    1483             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10