LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/basegfx/source/polygon - b2dpolypolygon.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 166 179 92.7 %
Date: 2013-07-09 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     7505431 : class ImplB2DPolyPolygon
      33             : {
      34             :     basegfx::B2DPolygonVector                   maPolygons;
      35             : 
      36             : public:
      37          75 :     ImplB2DPolyPolygon() : maPolygons()
      38             :     {
      39          75 :     }
      40             : 
      41     2274913 :     explicit ImplB2DPolyPolygon(const basegfx::B2DPolygon& rToBeCopied) :
      42     2274913 :         maPolygons(1,rToBeCopied)
      43             :     {
      44     2274913 :     }
      45             : 
      46       31251 :     bool operator==(const ImplB2DPolyPolygon& rPolygonList) const
      47             :     {
      48             :         // same polygon count?
      49       31251 :         if(maPolygons.size() != rPolygonList.maPolygons.size())
      50       19891 :             return false;
      51             : 
      52             :         // compare polygon content
      53       11360 :         if(!(maPolygons == rPolygonList.maPolygons))
      54        2036 :             return false;
      55             : 
      56        9324 :         return true;
      57             :     }
      58             : 
      59     7095004 :     const basegfx::B2DPolygon& getB2DPolygon(sal_uInt32 nIndex) const
      60             :     {
      61     7095004 :         return maPolygons[nIndex];
      62             :     }
      63             : 
      64        7172 :     void setB2DPolygon(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon)
      65             :     {
      66        7172 :         maPolygons[nIndex] = rPolygon;
      67        7172 :     }
      68             : 
      69      286956 :     void insert(sal_uInt32 nIndex, const basegfx::B2DPolygon& rPolygon, sal_uInt32 nCount)
      70             :     {
      71      286956 :         if(nCount)
      72             :         {
      73             :             // add nCount copies of rPolygon
      74      286956 :             basegfx::B2DPolygonVector::iterator aIndex(maPolygons.begin());
      75      286956 :             if( nIndex )
      76      141297 :                 aIndex += nIndex;
      77      286956 :             maPolygons.insert(aIndex, nCount, rPolygon);
      78             :         }
      79      286956 :     }
      80             : 
      81       15398 :     void insert(sal_uInt32 nIndex, const basegfx::B2DPolyPolygon& rPolyPolygon)
      82             :     {
      83             :         // add nCount polygons from rPolyPolygon
      84       15398 :         basegfx::B2DPolygonVector::iterator aIndex(maPolygons.begin());
      85       15398 :         if( nIndex )
      86        9104 :             aIndex += nIndex;
      87       15398 :         maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
      88       15398 :     }
      89             : 
      90         149 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
      91             :     {
      92         149 :         if(nCount)
      93             :         {
      94             :             // remove polygon data
      95         149 :             basegfx::B2DPolygonVector::iterator aStart(maPolygons.begin());
      96         149 :             aStart += nIndex;
      97         149 :             const basegfx::B2DPolygonVector::iterator aEnd(aStart + nCount);
      98             : 
      99         149 :             maPolygons.erase(aStart, aEnd);
     100             :         }
     101         149 :     }
     102             : 
     103    10161220 :     sal_uInt32 count() const
     104             :     {
     105    10161220 :         return maPolygons.size();
     106             :     }
     107             : 
     108        1895 :     void setClosed(bool bNew)
     109             :     {
     110        9807 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     111             :         {
     112        7912 :             maPolygons[a].setClosed(bNew);
     113             :         }
     114        1895 :     }
     115             : 
     116          21 :     void flip()
     117             :     {
     118             :         std::for_each( maPolygons.begin(),
     119             :                        maPolygons.end(),
     120          21 :                        std::mem_fun_ref( &basegfx::B2DPolygon::flip ));
     121          21 :     }
     122             : 
     123         297 :     void removeDoublePoints()
     124             :     {
     125             :         std::for_each( maPolygons.begin(),
     126             :                        maPolygons.end(),
     127         297 :                        std::mem_fun_ref( &basegfx::B2DPolygon::removeDoublePoints ));
     128         297 :     }
     129             : 
     130      190789 :     void transform(const basegfx::B2DHomMatrix& rMatrix)
     131             :     {
     132      464131 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     133             :         {
     134      273342 :             maPolygons[a].transform(rMatrix);
     135             :         }
     136      190789 :     }
     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       15398 :     const basegfx::B2DPolygon* begin() const
     146             :     {
     147       15398 :         if(maPolygons.empty())
     148           0 :             return 0;
     149             :         else
     150       15398 :             return &maPolygons.front();
     151             :     }
     152             : 
     153       15398 :     const basegfx::B2DPolygon* end() const
     154             :     {
     155       15398 :         if(maPolygons.empty())
     156           0 :             return 0;
     157             :         else
     158       15398 :             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      339582 :     B2DPolyPolygon::B2DPolyPolygon() :
     186      339582 :         mpPolyPolygon(DefaultPolyPolygon::get())
     187             :     {
     188      339582 :     }
     189             : 
     190     2620964 :     B2DPolyPolygon::B2DPolyPolygon(const B2DPolyPolygon& rPolyPolygon) :
     191     2620964 :         mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
     192             :     {
     193     2620964 :     }
     194             : 
     195     2274913 :     B2DPolyPolygon::B2DPolyPolygon(const B2DPolygon& rPolygon) :
     196     2274913 :         mpPolyPolygon( ImplB2DPolyPolygon(rPolygon) )
     197             :     {
     198     2274913 :     }
     199             : 
     200     5235294 :     B2DPolyPolygon::~B2DPolyPolygon()
     201             :     {
     202     5235294 :     }
     203             : 
     204      109270 :     B2DPolyPolygon& B2DPolyPolygon::operator=(const B2DPolyPolygon& rPolyPolygon)
     205             :     {
     206      109270 :         mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
     207      109270 :         return *this;
     208             :     }
     209             : 
     210          30 :     void B2DPolyPolygon::makeUnique()
     211             :     {
     212          30 :         mpPolyPolygon.make_unique();
     213          30 :         mpPolyPolygon->makeUnique();
     214          30 :     }
     215             : 
     216       45080 :     bool B2DPolyPolygon::operator==(const B2DPolyPolygon& rPolyPolygon) const
     217             :     {
     218       45080 :         if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
     219       13829 :             return true;
     220             : 
     221       31251 :         return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
     222             :     }
     223             : 
     224       20967 :     bool B2DPolyPolygon::operator!=(const B2DPolyPolygon& rPolyPolygon) const
     225             :     {
     226       20967 :         return !((*this) == rPolyPolygon);
     227             :     }
     228             : 
     229     5096900 :     sal_uInt32 B2DPolyPolygon::count() const
     230             :     {
     231     5096900 :         return mpPolyPolygon->count();
     232             :     }
     233             : 
     234     4804351 :     B2DPolygon B2DPolyPolygon::getB2DPolygon(sal_uInt32 nIndex) const
     235             :     {
     236             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)");
     237             : 
     238     4804351 :         return mpPolyPolygon->getB2DPolygon(nIndex);
     239             :     }
     240             : 
     241        7172 :     void B2DPolyPolygon::setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon& rPolygon)
     242             :     {
     243             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B2DPolyPolygon access outside range (!)");
     244             : 
     245        7172 :         if(getB2DPolygon(nIndex) != rPolygon)
     246        7172 :             mpPolyPolygon->setB2DPolygon(nIndex, rPolygon);
     247        7172 :     }
     248             : 
     249     2198339 :     bool B2DPolyPolygon::areControlPointsUsed() const
     250             :     {
     251     4440970 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     252             :         {
     253     2246289 :             const B2DPolygon& rPolygon = mpPolyPolygon->getB2DPolygon(a);
     254             : 
     255     2246289 :             if(rPolygon.areControlPointsUsed())
     256             :             {
     257        3658 :                 return true;
     258             :             }
     259             :         }
     260             : 
     261     2194681 :         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      286956 :     void B2DPolyPolygon::append(const B2DPolygon& rPolygon, sal_uInt32 nCount)
     273             :     {
     274      286956 :         if(nCount)
     275      286956 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
     276      286956 :     }
     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       16561 :     B2DRange B2DPolyPolygon::getB2DRange() const
     291             :     {
     292       16561 :         B2DRange aRetval;
     293             : 
     294       35016 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     295             :         {
     296       18455 :             aRetval.expand(mpPolyPolygon->getB2DPolygon(a).getB2DRange());
     297             :         }
     298             : 
     299       16561 :         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       15388 :     void B2DPolyPolygon::append(const B2DPolyPolygon& rPolyPolygon)
     311             :     {
     312       15388 :         if(rPolyPolygon.count())
     313       15378 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
     314       15388 :     }
     315             : 
     316         149 :     void B2DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     317             :     {
     318             :         OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B2DPolyPolygon Remove outside range (!)");
     319             : 
     320         149 :         if(nCount)
     321         149 :             mpPolyPolygon->remove(nIndex, nCount);
     322         149 :     }
     323             : 
     324        6111 :     void B2DPolyPolygon::clear()
     325             :     {
     326        6111 :         mpPolyPolygon = DefaultPolyPolygon::get();
     327        6111 :     }
     328             : 
     329        9315 :     bool B2DPolyPolygon::isClosed() const
     330             :     {
     331        9315 :         bool bRetval(true);
     332             : 
     333             :         // PolyPOlygon is closed when all contained Polygons are closed or
     334             :         // no Polygon exists.
     335       20635 :         for(sal_uInt32 a(0L); bRetval && a < mpPolyPolygon->count(); a++)
     336             :         {
     337       11320 :             if(!(mpPolyPolygon->getB2DPolygon(a)).isClosed())
     338             :             {
     339        4384 :                 bRetval = false;
     340             :             }
     341             :         }
     342             : 
     343        9315 :         return bRetval;
     344             :     }
     345             : 
     346        1989 :     void B2DPolyPolygon::setClosed(bool bNew)
     347             :     {
     348        1989 :         if(bNew != isClosed())
     349        1895 :             mpPolyPolygon->setClosed(bNew);
     350        1989 :     }
     351             : 
     352          21 :     void B2DPolyPolygon::flip()
     353             :     {
     354          21 :         if(mpPolyPolygon->count())
     355             :         {
     356          21 :             mpPolyPolygon->flip();
     357             :         }
     358          21 :     }
     359             : 
     360        7770 :     bool B2DPolyPolygon::hasDoublePoints() const
     361             :     {
     362        7770 :         bool bRetval(false);
     363             : 
     364       22359 :         for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
     365             :         {
     366       14589 :             if((mpPolyPolygon->getB2DPolygon(a)).hasDoublePoints())
     367             :             {
     368         297 :                 bRetval = true;
     369             :             }
     370             :         }
     371             : 
     372        7770 :         return bRetval;
     373             :     }
     374             : 
     375        7770 :     void B2DPolyPolygon::removeDoublePoints()
     376             :     {
     377        7770 :         if(hasDoublePoints())
     378         297 :             mpPolyPolygon->removeDoublePoints();
     379        7770 :     }
     380             : 
     381      247666 :     void B2DPolyPolygon::transform(const B2DHomMatrix& rMatrix)
     382             :     {
     383      247666 :         if(mpPolyPolygon->count() && !rMatrix.isIdentity())
     384             :         {
     385      190789 :             mpPolyPolygon->transform(rMatrix);
     386             :         }
     387      247666 :     }
     388             : 
     389       15398 :     const B2DPolygon* B2DPolyPolygon::begin() const
     390             :     {
     391       15398 :         return mpPolyPolygon->begin();
     392             :     }
     393             : 
     394       15398 :     const B2DPolygon* B2DPolyPolygon::end() const
     395             :     {
     396       15398 :         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