LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/basegfx/source/polygon - b3dpolypolygon.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 119 188 63.3 %
Date: 2013-07-09 Functions: 36 53 67.9 %
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/b3dpolypolygon.hxx>
      22             : #include <basegfx/polygon/b3dpolygon.hxx>
      23             : #include <rtl/instance.hxx>
      24             : #include <basegfx/matrix/b2dhommatrix.hxx>
      25             : #include <basegfx/matrix/b3dhommatrix.hxx>
      26             : #include <functional>
      27             : #include <vector>
      28             : #include <algorithm>
      29             : 
      30             : //////////////////////////////////////////////////////////////////////////////
      31             : 
      32       30137 : class ImplB3DPolyPolygon
      33             : {
      34             :     typedef ::std::vector< ::basegfx::B3DPolygon >  PolygonVector;
      35             : 
      36             :     PolygonVector                                   maPolygons;
      37             : 
      38             : public:
      39           1 :     ImplB3DPolyPolygon() : maPolygons()
      40             :     {
      41           1 :     }
      42             : 
      43         106 :     explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
      44         106 :         maPolygons(1,rToBeCopied)
      45             :     {
      46         106 :     }
      47             : 
      48        5832 :     bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
      49             :     {
      50             :         // same polygon count?
      51        5832 :         if(maPolygons.size() != rPolygonList.maPolygons.size())
      52         480 :             return false;
      53             : 
      54             :         // compare polygon content
      55        5352 :         if(maPolygons != rPolygonList.maPolygons)
      56           0 :             return false;
      57             : 
      58        5352 :         return true;
      59             :     }
      60             : 
      61       38790 :     const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
      62             :     {
      63       38790 :         return maPolygons[nIndex];
      64             :     }
      65             : 
      66        5402 :     void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
      67             :     {
      68        5402 :         maPolygons[nIndex] = rPolygon;
      69        5402 :     }
      70             : 
      71        9274 :     void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
      72             :     {
      73        9274 :         if(nCount)
      74             :         {
      75             :             // add nCount copies of rPolygon
      76        9274 :             PolygonVector::iterator aIndex(maPolygons.begin());
      77        9274 :             if( nIndex )
      78         792 :                 aIndex += nIndex;
      79        9274 :             maPolygons.insert(aIndex, nCount, rPolygon);
      80             :         }
      81        9274 :     }
      82             : 
      83           0 :     void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
      84             :     {
      85             :         // add all polygons from rPolyPolygon
      86           0 :         PolygonVector::iterator aIndex(maPolygons.begin());
      87           0 :         if( nIndex )
      88           0 :             aIndex += nIndex;
      89           0 :         maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
      90           0 :     }
      91             : 
      92           0 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
      93             :     {
      94           0 :         if(nCount)
      95             :         {
      96             :             // remove polygon data
      97           0 :             PolygonVector::iterator aStart(maPolygons.begin());
      98           0 :             aStart += nIndex;
      99           0 :             const PolygonVector::iterator aEnd(aStart + nCount);
     100             : 
     101           0 :             maPolygons.erase(aStart, aEnd);
     102             :         }
     103           0 :     }
     104             : 
     105       77024 :     sal_uInt32 count() const
     106             :     {
     107       77024 :         return maPolygons.size();
     108             :     }
     109             : 
     110             :     void setClosed(bool bNew)
     111             :     {
     112             :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     113             :         {
     114             :             maPolygons[a].setClosed(bNew);
     115             :         }
     116             :     }
     117             : 
     118        5690 :     void flip()
     119             :     {
     120             :         std::for_each( maPolygons.begin(),
     121             :                        maPolygons.end(),
     122        5690 :                        std::mem_fun_ref( &::basegfx::B3DPolygon::flip ));
     123        5690 :     }
     124             : 
     125           0 :     void removeDoublePoints()
     126             :     {
     127             :         std::for_each( maPolygons.begin(),
     128             :                        maPolygons.end(),
     129           0 :                        std::mem_fun_ref( &::basegfx::B3DPolygon::removeDoublePoints ));
     130           0 :     }
     131             : 
     132        4487 :     void transform(const ::basegfx::B3DHomMatrix& rMatrix)
     133             :     {
     134        9694 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     135             :         {
     136        5207 :             maPolygons[a].transform(rMatrix);
     137             :         }
     138        4487 :     }
     139             : 
     140           0 :     void clearBColors()
     141             :     {
     142           0 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     143             :         {
     144           0 :             maPolygons[a].clearBColors();
     145             :         }
     146           0 :     }
     147             : 
     148          66 :     void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
     149             :     {
     150         132 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     151             :         {
     152          66 :             maPolygons[a].transformNormals(rMatrix);
     153             :         }
     154          66 :     }
     155             : 
     156         127 :     void clearNormals()
     157             :     {
     158         254 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     159             :         {
     160         127 :             maPolygons[a].clearNormals();
     161             :         }
     162         127 :     }
     163             : 
     164         261 :     void transformTextureCoordiantes(const ::basegfx::B2DHomMatrix& rMatrix)
     165             :     {
     166         522 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     167             :         {
     168         261 :             maPolygons[a].transformTextureCoordiantes(rMatrix);
     169             :         }
     170         261 :     }
     171             : 
     172         127 :     void clearTextureCoordinates()
     173             :     {
     174         254 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     175             :         {
     176         127 :             maPolygons[a].clearTextureCoordinates();
     177             :         }
     178         127 :     }
     179             : 
     180           0 :     const basegfx::B3DPolygon* begin() const
     181             :     {
     182           0 :         if(maPolygons.empty())
     183           0 :             return 0;
     184             :         else
     185           0 :             return &maPolygons.front();
     186             :     }
     187             : 
     188           0 :     const basegfx::B3DPolygon* end() const
     189             :     {
     190           0 :         if(maPolygons.empty())
     191           0 :             return 0;
     192             :         else
     193           0 :             return (&maPolygons.back())+1;
     194             :     }
     195             : 
     196           0 :     basegfx::B3DPolygon* begin()
     197             :     {
     198           0 :         if(maPolygons.empty())
     199           0 :             return 0;
     200             :         else
     201           0 :             return &maPolygons.front();
     202             :     }
     203             : 
     204           0 :     basegfx::B3DPolygon* end()
     205             :     {
     206           0 :         if(maPolygons.empty())
     207           0 :             return 0;
     208             :         else
     209           0 :             return &(maPolygons.back())+1;
     210             :     }
     211             : };
     212             : 
     213             : //////////////////////////////////////////////////////////////////////////////
     214             : 
     215             : namespace basegfx
     216             : {
     217             :     namespace { struct DefaultPolyPolygon : public rtl::Static<B3DPolyPolygon::ImplType,
     218             :                                                                DefaultPolyPolygon> {}; }
     219             : 
     220        8972 :     B3DPolyPolygon::B3DPolyPolygon() :
     221        8972 :         mpPolyPolygon(DefaultPolyPolygon::get())
     222             :     {
     223        8972 :     }
     224             : 
     225       30570 :     B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) :
     226       30570 :         mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
     227             :     {
     228       30570 :     }
     229             : 
     230         106 :     B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon& rPolygon) :
     231         106 :         mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
     232             :     {
     233         106 :     }
     234             : 
     235       39648 :     B3DPolyPolygon::~B3DPolyPolygon()
     236             :     {
     237       39648 :     }
     238             : 
     239         776 :     B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon)
     240             :     {
     241         776 :         mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
     242         776 :         return *this;
     243             :     }
     244             : 
     245        6846 :     bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
     246             :     {
     247        6846 :         if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
     248        1014 :             return true;
     249             : 
     250        5832 :         return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
     251             :     }
     252             : 
     253         528 :     bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
     254             :     {
     255         528 :         return !(*this == rPolyPolygon);
     256             :     }
     257             : 
     258       58667 :     sal_uInt32 B3DPolyPolygon::count() const
     259             :     {
     260       58667 :         return mpPolyPolygon->count();
     261             :     }
     262             : 
     263       37465 :     B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
     264             :     {
     265             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
     266             : 
     267       37465 :         return mpPolyPolygon->getB3DPolygon(nIndex);
     268             :     }
     269             : 
     270        5402 :     void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
     271             :     {
     272             :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
     273             : 
     274        5402 :         if(getB3DPolygon(nIndex) != rPolygon)
     275        5402 :             mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
     276        5402 :     }
     277             : 
     278         117 :     bool B3DPolyPolygon::areBColorsUsed() const
     279             :     {
     280         234 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     281             :         {
     282         117 :             if((mpPolyPolygon->getB3DPolygon(a)).areBColorsUsed())
     283             :             {
     284           0 :                 return true;
     285             :             }
     286             :         }
     287             : 
     288         117 :         return false;
     289             :     }
     290             : 
     291         117 :     void B3DPolyPolygon::clearBColors()
     292             :     {
     293         117 :         if(areBColorsUsed())
     294           0 :             mpPolyPolygon->clearBColors();
     295         117 :     }
     296             : 
     297         216 :     void B3DPolyPolygon::transformNormals(const B3DHomMatrix& rMatrix)
     298             :     {
     299         216 :         if(!rMatrix.isIdentity())
     300          66 :             mpPolyPolygon->transformNormals(rMatrix);
     301         216 :     }
     302             : 
     303         772 :     bool B3DPolyPolygon::areNormalsUsed() const
     304             :     {
     305        1123 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     306             :         {
     307         772 :             if((mpPolyPolygon->getB3DPolygon(a)).areNormalsUsed())
     308             :             {
     309         421 :                 return true;
     310             :             }
     311             :         }
     312             : 
     313         351 :         return false;
     314             :     }
     315             : 
     316         244 :     void B3DPolyPolygon::clearNormals()
     317             :     {
     318         244 :         if(areNormalsUsed())
     319         127 :             mpPolyPolygon->clearNormals();
     320         244 :     }
     321             : 
     322         261 :     void B3DPolyPolygon::transformTextureCoordiantes(const B2DHomMatrix& rMatrix)
     323             :     {
     324         261 :         if(!rMatrix.isIdentity())
     325         261 :             mpPolyPolygon->transformTextureCoordiantes(rMatrix);
     326         261 :     }
     327             : 
     328         436 :     bool B3DPolyPolygon::areTextureCoordinatesUsed() const
     329             :     {
     330         436 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     331             :         {
     332         436 :             if((mpPolyPolygon->getB3DPolygon(a)).areTextureCoordinatesUsed())
     333             :             {
     334         436 :                 return true;
     335             :             }
     336             :         }
     337             : 
     338           0 :         return false;
     339             :     }
     340             : 
     341         127 :     void B3DPolyPolygon::clearTextureCoordinates()
     342             :     {
     343         127 :         if(areTextureCoordinatesUsed())
     344         127 :             mpPolyPolygon->clearTextureCoordinates();
     345         127 :     }
     346             : 
     347        9274 :     void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
     348             :     {
     349        9274 :         if(nCount)
     350        9274 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
     351        9274 :     }
     352             : 
     353           0 :     void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
     354             :     {
     355           0 :         if(rPolyPolygon.count())
     356           0 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
     357           0 :     }
     358             : 
     359           0 :     void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     360             :     {
     361             :         OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)");
     362             : 
     363           0 :         if(nCount)
     364           0 :             mpPolyPolygon->remove(nIndex, nCount);
     365           0 :     }
     366             : 
     367           0 :     void B3DPolyPolygon::clear()
     368             :     {
     369           0 :         mpPolyPolygon = DefaultPolyPolygon::get();
     370           0 :     }
     371             : 
     372        5690 :     void B3DPolyPolygon::flip()
     373             :     {
     374        5690 :         mpPolyPolygon->flip();
     375        5690 :     }
     376             : 
     377           0 :     bool B3DPolyPolygon::hasDoublePoints() const
     378             :     {
     379           0 :         bool bRetval(false);
     380             : 
     381           0 :         for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
     382             :         {
     383           0 :             if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints())
     384             :             {
     385           0 :                 bRetval = true;
     386             :             }
     387             :         }
     388             : 
     389           0 :         return bRetval;
     390             :     }
     391             : 
     392           0 :     void B3DPolyPolygon::removeDoublePoints()
     393             :     {
     394           0 :         if(hasDoublePoints())
     395           0 :             mpPolyPolygon->removeDoublePoints();
     396           0 :     }
     397             : 
     398        7290 :     void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix)
     399             :     {
     400        7290 :         if(mpPolyPolygon->count() && !rMatrix.isIdentity())
     401             :         {
     402        4487 :             mpPolyPolygon->transform(rMatrix);
     403             :         }
     404        7290 :     }
     405             : 
     406           0 :     const B3DPolygon* B3DPolyPolygon::begin() const
     407             :     {
     408           0 :         return mpPolyPolygon->begin();
     409             :     }
     410             : 
     411           0 :     const B3DPolygon* B3DPolyPolygon::end() const
     412             :     {
     413           0 :         return mpPolyPolygon->end();
     414             :     }
     415             : 
     416           0 :     B3DPolygon* B3DPolyPolygon::begin()
     417             :     {
     418           0 :         return mpPolyPolygon->begin();
     419             :     }
     420             : 
     421           0 :     B3DPolygon* B3DPolyPolygon::end()
     422             :     {
     423           0 :         return mpPolyPolygon->end();
     424             :     }
     425             : } // end of namespace basegfx
     426             : 
     427             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10