LCOV - code coverage report
Current view: top level - basegfx/source/polygon - b2dpolypolygon.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 166 179 92.7 %
Date: 2014-04-11 Functions: 48 50 96.0 %
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 <basegfx/polygon/b2dpolypolygon.hxx>
      21             : #include <osl/diagnose.h>
      22             : #include <basegfx/polygon/b2dpolygon.hxx>
      23             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      24             : #include <rtl/instance.hxx>
      25             : #include <basegfx/matrix/b2dhommatrix.hxx>
      26             : 
      27             : #include <functional>
      28             : #include <algorithm>
      29             : 
      30             : 
      31             : 
      32     8921268 : class ImplB2DPolyPolygon
      33             : {
      34             :     basegfx::B2DPolygonVector                   maPolygons;
      35             : 
      36             : public:
      37          83 :     ImplB2DPolyPolygon() : maPolygons()
      38             :     {
      39          83 :     }
      40             : 
      41     2711715 :     explicit ImplB2DPolyPolygon(const basegfx::B2DPolygon& rToBeCopied) :
      42     2711715 :         maPolygons(1,rToBeCopied)
      43             :     {
      44     2711715 :     }
      45             : 
      46       36414 :     bool operator==(const ImplB2DPolyPolygon& rPolygonList) const
      47             :     {
      48             :         // same polygon count?
      49       36414 :         if(maPolygons.size() != rPolygonList.maPolygons.size())
      50       23448 :             return false;
      51             : 
      52             :         // compare polygon content
      53       12966 :         if(!(maPolygons == rPolygonList.maPolygons))
      54        2848 :             return false;
      55             : 
      56       10118 :         return true;
      57             :     }
      58             : 
      59     8600164 :     const basegfx::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const
      60             :     {
      61     8600164 :         return maPolygons[nIndex];
      62             :     }
      63             : 
      64        4526 :     void setB2DPolygon(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon)
      65             :     {
      66        4526 :         maPolygons[nIndex] = rPolygon;
      67        4526 :     }
      68             : 
      69      326061 :     void insert(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount)
      70             :     {
      71      326061 :         if(nCount)
      72             :         {
      73             :             // add nCount copies of rPolygon
      74      326061 :             basegfx::B2DPolygonVector::iterator aIndex(maPolygons.begin());
      75      326061 :             if( nIndex )
      76      160175 :                 aIndex += nIndex;
      77      326061 :             maPolygons.insert(aIndex, nCount, rPolygon);
      78             :         }
      79      326061 :     }
      80             : 
      81       18703 :     void insert(sal_uInt32 nIndex, const basegfx::B2DPolyPolygon& rPolyPolygon)
      82             :     {
      83             :         // add nCount polygons from rPolyPolygon
      84       18703 :         basegfx::B2DPolygonVector::iterator aIndex(maPolygons.begin());
      85       18703 :         if( nIndex )
      86       11583 :             aIndex += nIndex;
      87       18703 :         maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
      88       18703 :     }
      89             : 
      90         141 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
      91             :     {
      92         141 :         if(nCount)
      93             :         {
      94             :             // remove polygon data
      95         141 :             basegfx::B2DPolygonVector::iterator aStart(maPolygons.begin());
      96         141 :             aStart += nIndex;
      97         141 :             const basegfx::B2DPolygonVector::iterator aEnd(aStart + nCount);
      98             : 
      99         141 :             maPolygons.erase(aStart, aEnd);
     100             :         }
     101         141 :     }
     102             : 
     103    12426834 :     sal_uInt32 count() const
     104             :     {
     105    12426834 :         return maPolygons.size();
     106             :     }
     107             : 
     108        2295 :     void setClosed(bool bNew)
     109             :     {
     110       17279 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     111             :         {
     112       14984 :             maPolygons[a].setClosed(bNew);
     113             :         }
     114        2295 :     }
     115             : 
     116          29 :     void flip()
     117             :     {
     118             :         std::for_each( maPolygons.begin(),
     119             :                        maPolygons.end(),
     120          29 :                        std::mem_fun_ref( &basegfx::B2DPolygon::flip ));
     121          29 :     }
     122             : 
     123         532 :     void removeDoublePoints()
     124             :     {
     125             :         std::for_each( maPolygons.begin(),
     126             :                        maPolygons.end(),
     127         532 :                        std::mem_fun_ref( &basegfx::B2DPolygon::removeDoublePoints ));
     128         532 :     }
     129             : 
     130      240743 :     void transform(const basegfx::B2DHomMatrix& rMatrix)
     131             :     {
     132      586391 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     133             :         {
     134      345648 :             maPolygons[a].transform(rMatrix);
     135             :         }
     136      240743 :     }
     137             : 
     138          30 :     void makeUnique()
     139             :     {
     140             :         std::for_each( maPolygons.begin(),
     141             :                        maPolygons.end(),
     142          30 :                        std::mem_fun_ref( &basegfx::B2DPolygon::makeUnique ));
     143          30 :     }
     144             : 
     145       18703 :     const basegfx::B2DPolygon* begin() const
     146             :     {
     147       18703 :         if(maPolygons.empty())
     148           0 :             return 0;
     149             :         else
     150       18703 :             return &maPolygons.front();
     151             :     }
     152             : 
     153       18703 :     const basegfx::B2DPolygon* end() const
     154             :     {
     155       18703 :         if(maPolygons.empty())
     156           0 :             return 0;
     157             :         else
     158       18703 :             return (&maPolygons.back())+1;
     159             :     }
     160             : 
     161          53 :     basegfx::B2DPolygon* begin()
     162             :     {
     163          53 :         if(maPolygons.empty())
     164           0 :             return 0;
     165             :         else
     166          53 :             return &maPolygons.front();
     167             :     }
     168             : 
     169          53 :     basegfx::B2DPolygon* end()
     170             :     {
     171          53 :         if(maPolygons.empty())
     172           0 :             return 0;
     173             :         else
     174          53 :             return &(maPolygons.back())+1;
     175             :     }
     176             : };
     177             : 
     178             : 
     179             : 
     180             : namespace basegfx
     181             : {
     182             :     namespace { struct DefaultPolyPolygon: public rtl::Static<B2DPolyPolygon::ImplType,
     183             :                                                               DefaultPolyPolygon> {}; }
     184             : 
     185      398706 :     B2DPolyPolygon::B2DPolyPolygon() :
     186      398706 :         mpPolyPolygon(DefaultPolyPolygon::get())
     187             :     {
     188      398706 :     }
     189             : 
     190     3129606 :     B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) :
     191     3129606 :         mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
     192             :     {
     193     3129606 :     }
     194             : 
     195     2711715 :     B2DPolyPolygon::B2DPolyPolygon(const B2DPolygon& rPolygon) :
     196     2711715 :         mpPolyPolygon( ImplB2DPolyPolygon(rPolygon) )
     197             :     {
     198     2711715 :     }
     199             : 
     200     6226040 :     B2DPolyPolygon::~B2DPolyPolygon()
     201             :     {
     202     6226040 :     }
     203             : 
     204      106575 :     B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon)
     205             :     {
     206      106575 :         mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
     207      106575 :         return *this;
     208             :     }
     209             : 
     210          30 :     void B2DPolyPolygon::makeUnique()
     211             :     {
     212          30 :         mpPolyPolygon.make_unique();
     213          30 :         mpPolyPolygon->makeUnique();
     214          30 :     }
     215             : 
     216       42638 :     bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const
     217             :     {
     218       42638 :         if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
     219        6224 :             return true;
     220             : 
     221       36414 :         return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
     222             :     }
     223             : 
     224       24873 :     bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const
     225             :     {
     226       24873 :         return !((*this) == rPolyPolygon);
     227             :     }
     228             : 
     229     6356270 :     sal_uInt32 B2DPolyPolygon::count() const
     230             :     {
     231     6356270 :         return mpPolyPolygon->count();
     232             :     }
     233             : 
     234     5844699 :     B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const
     235             :     {
     236             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)");
     237             : 
     238     5844699 :         return mpPolyPolygon->getB2DPolygon(nIndex);
     239             :     }
     240             : 
     241        4526 :     void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon)
     242             :     {
     243             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)");
     244             : 
     245        4526 :         if(getB2DPolygon(nIndex) != rPolygon)
     246        4526 :             mpPolyPolygon->setB2DPolygon(nIndex, rPolygon);
     247        4526 :     }
     248             : 
     249     2629219 :     bool B2DPolyPolygon::areControlPointsUsed() const
     250             :     {
     251     5323453 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     252             :         {
     253     2698671 :             const B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a);
     254             : 
     255     2698671 :             if(rPolygon.areControlPointsUsed())
     256             :             {
     257        4437 :                 return true;
     258             :             }
     259             :         }
     260             : 
     261     2624782 :         return false;
     262             :     }
     263             : 
     264           0 :     void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolygon& rPolygon, sal_uInt32 nCount)
     265             :     {
     266             :         OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)");
     267             : 
     268           0 :         if(nCount)
     269           0 :             mpPolyPolygon->insert(nIndex, rPolygon, nCount);
     270           0 :     }
     271             : 
     272      326061 :     void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount)
     273             :     {
     274      326061 :         if(nCount)
     275      326061 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
     276      326061 :     }
     277             : 
     278           0 :     B2DPolyPolygon B2DPolyPolygon::getDefaultAdaptiveSubdivision() const
     279             :     {
     280           0 :         B2DPolyPolygon aRetval;
     281             : 
     282           0 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     283             :         {
     284           0 :             aRetval.append(mpPolyPolygon->getB2DPolygon(a).getDefaultAdaptiveSubdivision());
     285             :         }
     286             : 
     287           0 :         return aRetval;
     288             :     }
     289             : 
     290       17265 :     B2DRange B2DPolyPolygon::getB2DRange() const
     291             :     {
     292       17265 :         B2DRange aRetval;
     293             : 
     294       37148 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     295             :         {
     296       19883 :             aRetval.expand(mpPolyPolygon->getB2DPolygon(a).getB2DRange());
     297             :         }
     298             : 
     299       17265 :         return aRetval;
     300             :     }
     301             : 
     302          20 :     void B2DPolyPolygon::insert(sal_uInt32 nIndex, const B2DPolyPolygon& rPolyPolygon)
     303             :     {
     304             :         OSL_ENSURE(nIndex <= mpPolyPolygon->count(), "B2DPolyPolygon Insert outside range (!)");
     305             : 
     306          20 :         if(rPolyPolygon.count())
     307          20 :             mpPolyPolygon->insert(nIndex, rPolyPolygon);
     308          20 :     }
     309             : 
     310       18748 :     void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon)
     311             :     {
     312       18748 :         if(rPolyPolygon.count())
     313       18683 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
     314       18748 :     }
     315             : 
     316         141 :     void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     317             :     {
     318             :         OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)");
     319             : 
     320         141 :         if(nCount)
     321         141 :             mpPolyPolygon->remove(nIndex, nCount);
     322         141 :     }
     323             : 
     324        6735 :     void B2DPolyPolygon::clear()
     325             :     {
     326        6735 :         mpPolyPolygon = DefaultPolyPolygon::get();
     327        6735 :     }
     328             : 
     329       15472 :     bool B2DPolyPolygon::isClosed() const
     330             :     {
     331       15472 :         bool bRetval(true);
     332             : 
     333             :         // PolyPOlygon is closed when all contained Polygons are closed or
     334             :         // no Polygon exists.
     335       40369 :         for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++)
     336             :         {
     337       24897 :             if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed())
     338             :             {
     339        6156 :                 bRetval = false;
     340             :             }
     341             :         }
     342             : 
     343       15472 :         return bRetval;
     344             :     }
     345             : 
     346        3420 :     void B2DPolyPolygon::setClosed(bool bNew)
     347             :     {
     348        3420 :         if(bNew != isClosed())
     349        2295 :             mpPolyPolygon->setClosed(bNew);
     350        3420 :     }
     351             : 
     352          29 :     void B2DPolyPolygon::flip()
     353             :     {
     354          29 :         if(mpPolyPolygon->count())
     355             :         {
     356          29 :             mpPolyPolygon->flip();
     357             :         }
     358          29 :     }
     359             : 
     360        6740 :     bool B2DPolyPolygon::hasDoublePoints() const
     361             :     {
     362        6740 :         bool bRetval(false);
     363             : 
     364       18754 :         for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
     365             :         {
     366       12014 :             if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints())
     367             :             {
     368         532 :                 bRetval = true;
     369             :             }
     370             :         }
     371             : 
     372        6740 :         return bRetval;
     373             :     }
     374             : 
     375        6740 :     void B2DPolyPolygon::removeDoublePoints()
     376             :     {
     377        6740 :         if(hasDoublePoints())
     378         532 :             mpPolyPolygon->removeDoublePoints();
     379        6740 :     }
     380             : 
     381      312755 :     void B2DPolyPolygon::transform(const B2DHomMatrix& rMatrix)
     382             :     {
     383      312755 :         if(mpPolyPolygon->count() && !rMatrix.isIdentity())
     384             :         {
     385      240743 :             mpPolyPolygon->transform(rMatrix);
     386             :         }
     387      312755 :     }
     388             : 
     389       18703 :     const B2DPolygon* B2DPolyPolygon::begin() const
     390             :     {
     391       18703 :         return mpPolyPolygon->begin();
     392             :     }
     393             : 
     394       18703 :     const B2DPolygon* B2DPolyPolygon::end() const
     395             :     {
     396       18703 :         return mpPolyPolygon->end();
     397             :     }
     398             : 
     399          53 :     B2DPolygon* B2DPolyPolygon::begin()
     400             :     {
     401          53 :         return mpPolyPolygon->begin();
     402             :     }
     403             : 
     404          53 :     B2DPolygon* B2DPolyPolygon::end()
     405             :     {
     406          53 :         return mpPolyPolygon->end();
     407             :     }
     408             : } // end of namespace basegfx
     409             : 
     410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10