LCOV - code coverage report
Current view: top level - basegfx/source/polygon - b3dpolypolygon.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 119 188 63.3 %
Date: 2012-08-25 Functions: 36 53 67.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 45 104 43.3 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <osl/diagnose.h>
      30                 :            : #include <basegfx/polygon/b3dpolypolygon.hxx>
      31                 :            : #include <basegfx/polygon/b3dpolygon.hxx>
      32                 :            : #include <rtl/instance.hxx>
      33                 :            : #include <basegfx/matrix/b2dhommatrix.hxx>
      34                 :            : #include <basegfx/matrix/b3dhommatrix.hxx>
      35                 :            : #include <functional>
      36                 :            : #include <vector>
      37                 :            : #include <algorithm>
      38                 :            : 
      39                 :            : //////////////////////////////////////////////////////////////////////////////
      40                 :            : 
      41                 :      53520 : class ImplB3DPolyPolygon
      42                 :            : {
      43                 :            :     typedef ::std::vector< ::basegfx::B3DPolygon >  PolygonVector;
      44                 :            : 
      45                 :            :     PolygonVector                                   maPolygons;
      46                 :            : 
      47                 :            : public:
      48                 :          2 :     ImplB3DPolyPolygon() : maPolygons()
      49                 :            :     {
      50                 :          2 :     }
      51                 :            : 
      52                 :        114 :     explicit ImplB3DPolyPolygon(const ::basegfx::B3DPolygon& rToBeCopied) :
      53         [ +  - ]:        114 :         maPolygons(1,rToBeCopied)
      54                 :            :     {
      55                 :        114 :     }
      56                 :            : 
      57                 :      10186 :     bool operator==(const ImplB3DPolyPolygon& rPolygonList) const
      58                 :            :     {
      59                 :            :         // same polygon count?
      60         [ +  + ]:      10186 :         if(maPolygons.size() != rPolygonList.maPolygons.size())
      61                 :        876 :             return false;
      62                 :            : 
      63                 :            :         // compare polygon content
      64         [ -  + ]:       9310 :         if(maPolygons != rPolygonList.maPolygons)
      65                 :          0 :             return false;
      66                 :            : 
      67                 :      10186 :         return true;
      68                 :            :     }
      69                 :            : 
      70                 :      69850 :     const ::basegfx::B3DPolygon& getB3DPolygon(sal_uInt32 nIndex) const
      71                 :            :     {
      72                 :      69850 :         return maPolygons[nIndex];
      73                 :            :     }
      74                 :            : 
      75                 :       9479 :     void setB3DPolygon(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon)
      76                 :            :     {
      77                 :       9479 :         maPolygons[nIndex] = rPolygon;
      78                 :       9479 :     }
      79                 :            : 
      80                 :      15795 :     void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolygon& rPolygon, sal_uInt32 nCount)
      81                 :            :     {
      82         [ +  - ]:      15795 :         if(nCount)
      83                 :            :         {
      84                 :            :             // add nCount copies of rPolygon
      85                 :      15795 :             PolygonVector::iterator aIndex(maPolygons.begin());
      86         [ +  + ]:      15795 :             if( nIndex )
      87         [ +  - ]:        792 :                 aIndex += nIndex;
      88         [ +  - ]:      15795 :             maPolygons.insert(aIndex, nCount, rPolygon);
      89                 :            :         }
      90                 :      15795 :     }
      91                 :            : 
      92                 :          0 :     void insert(sal_uInt32 nIndex, const ::basegfx::B3DPolyPolygon& rPolyPolygon)
      93                 :            :     {
      94                 :            :         // add all polygons from rPolyPolygon
      95                 :          0 :         PolygonVector::iterator aIndex(maPolygons.begin());
      96         [ #  # ]:          0 :         if( nIndex )
      97         [ #  # ]:          0 :             aIndex += nIndex;
      98 [ #  # ][ #  # ]:          0 :         maPolygons.insert(aIndex, rPolyPolygon.begin(), rPolyPolygon.end());
                 [ #  # ]
      99                 :          0 :     }
     100                 :            : 
     101                 :          0 :     void remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     102                 :            :     {
     103         [ #  # ]:          0 :         if(nCount)
     104                 :            :         {
     105                 :            :             // remove polygon data
     106                 :          0 :             PolygonVector::iterator aStart(maPolygons.begin());
     107         [ #  # ]:          0 :             aStart += nIndex;
     108         [ #  # ]:          0 :             const PolygonVector::iterator aEnd(aStart + nCount);
     109                 :            : 
     110         [ #  # ]:          0 :             maPolygons.erase(aStart, aEnd);
     111                 :            :         }
     112                 :          0 :     }
     113                 :            : 
     114                 :     138929 :     sal_uInt32 count() const
     115                 :            :     {
     116                 :     138929 :         return maPolygons.size();
     117                 :            :     }
     118                 :            : 
     119                 :            :     void setClosed(bool bNew)
     120                 :            :     {
     121                 :            :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     122                 :            :         {
     123                 :            :             maPolygons[a].setClosed(bNew);
     124                 :            :         }
     125                 :            :     }
     126                 :            : 
     127                 :      10158 :     void flip()
     128                 :            :     {
     129                 :            :         std::for_each( maPolygons.begin(),
     130                 :            :                        maPolygons.end(),
     131                 :      10158 :                        std::mem_fun_ref( &::basegfx::B3DPolygon::flip ));
     132                 :      10158 :     }
     133                 :            : 
     134                 :          0 :     void removeDoublePoints()
     135                 :            :     {
     136                 :            :         std::for_each( maPolygons.begin(),
     137                 :            :                        maPolygons.end(),
     138                 :          0 :                        std::mem_fun_ref( &::basegfx::B3DPolygon::removeDoublePoints ));
     139                 :          0 :     }
     140                 :            : 
     141                 :       8150 :     void transform(const ::basegfx::B3DHomMatrix& rMatrix)
     142                 :            :     {
     143         [ +  + ]:      17020 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     144                 :            :         {
     145                 :       8870 :             maPolygons[a].transform(rMatrix);
     146                 :            :         }
     147                 :       8150 :     }
     148                 :            : 
     149                 :          0 :     void clearBColors()
     150                 :            :     {
     151         [ #  # ]:          0 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     152                 :            :         {
     153                 :          0 :             maPolygons[a].clearBColors();
     154                 :            :         }
     155                 :          0 :     }
     156                 :            : 
     157                 :         66 :     void transformNormals(const ::basegfx::B3DHomMatrix& rMatrix)
     158                 :            :     {
     159         [ +  + ]:        132 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     160                 :            :         {
     161                 :         66 :             maPolygons[a].transformNormals(rMatrix);
     162                 :            :         }
     163                 :         66 :     }
     164                 :            : 
     165                 :        283 :     void clearNormals()
     166                 :            :     {
     167         [ +  + ]:        566 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     168                 :            :         {
     169                 :        283 :             maPolygons[a].clearNormals();
     170                 :            :         }
     171                 :        283 :     }
     172                 :            : 
     173                 :        409 :     void transformTextureCoordiantes(const ::basegfx::B2DHomMatrix& rMatrix)
     174                 :            :     {
     175         [ +  + ]:        818 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     176                 :            :         {
     177                 :        409 :             maPolygons[a].transformTextureCoordiantes(rMatrix);
     178                 :            :         }
     179                 :        409 :     }
     180                 :            : 
     181                 :        505 :     void clearTextureCoordinates()
     182                 :            :     {
     183         [ +  + ]:       1010 :         for(sal_uInt32 a(0L); a < maPolygons.size(); a++)
     184                 :            :         {
     185                 :        505 :             maPolygons[a].clearTextureCoordinates();
     186                 :            :         }
     187                 :        505 :     }
     188                 :            : 
     189                 :          0 :     const basegfx::B3DPolygon* begin() const
     190                 :            :     {
     191         [ #  # ]:          0 :         if(maPolygons.empty())
     192                 :          0 :             return 0;
     193                 :            :         else
     194                 :          0 :             return &maPolygons.front();
     195                 :            :     }
     196                 :            : 
     197                 :          0 :     const basegfx::B3DPolygon* end() const
     198                 :            :     {
     199         [ #  # ]:          0 :         if(maPolygons.empty())
     200                 :          0 :             return 0;
     201                 :            :         else
     202                 :          0 :             return (&maPolygons.back())+1;
     203                 :            :     }
     204                 :            : 
     205                 :          0 :     basegfx::B3DPolygon* begin()
     206                 :            :     {
     207         [ #  # ]:          0 :         if(maPolygons.empty())
     208                 :          0 :             return 0;
     209                 :            :         else
     210                 :          0 :             return &maPolygons.front();
     211                 :            :     }
     212                 :            : 
     213                 :          0 :     basegfx::B3DPolygon* end()
     214                 :            :     {
     215         [ #  # ]:          0 :         if(maPolygons.empty())
     216                 :          0 :             return 0;
     217                 :            :         else
     218                 :          0 :             return &(maPolygons.back())+1;
     219                 :            :     }
     220                 :            : };
     221                 :            : 
     222                 :            : //////////////////////////////////////////////////////////////////////////////
     223                 :            : 
     224                 :            : namespace basegfx
     225                 :            : {
     226                 :            :     namespace { struct DefaultPolyPolygon : public rtl::Static<B3DPolyPolygon::ImplType,
     227                 :            :                                                                DefaultPolyPolygon> {}; }
     228                 :            : 
     229                 :      15897 :     B3DPolyPolygon::B3DPolyPolygon() :
     230                 :      15897 :         mpPolyPolygon(DefaultPolyPolygon::get())
     231                 :            :     {
     232                 :      15897 :     }
     233                 :            : 
     234                 :      54047 :     B3DPolyPolygon::B3DPolyPolygon(const B3DPolyPolygon& rPolyPolygon) :
     235                 :      54047 :         mpPolyPolygon(rPolyPolygon.mpPolyPolygon)
     236                 :            :     {
     237                 :      54047 :     }
     238                 :            : 
     239                 :        114 :     B3DPolyPolygon::B3DPolyPolygon(const B3DPolygon& rPolygon) :
     240         [ +  - ]:        114 :         mpPolyPolygon( ImplB3DPolyPolygon(rPolygon) )
     241                 :            :     {
     242                 :        114 :     }
     243                 :            : 
     244                 :      70058 :     B3DPolyPolygon::~B3DPolyPolygon()
     245                 :            :     {
     246                 :      70058 :     }
     247                 :            : 
     248                 :       1180 :     B3DPolyPolygon& B3DPolyPolygon::operator=(const B3DPolyPolygon& rPolyPolygon)
     249                 :            :     {
     250                 :       1180 :         mpPolyPolygon = rPolyPolygon.mpPolyPolygon;
     251                 :       1180 :         return *this;
     252                 :            :     }
     253                 :            : 
     254                 :      10186 :     bool B3DPolyPolygon::operator==(const B3DPolyPolygon& rPolyPolygon) const
     255                 :            :     {
     256         [ -  + ]:      10186 :         if(mpPolyPolygon.same_object(rPolyPolygon.mpPolyPolygon))
     257                 :          0 :             return true;
     258                 :            : 
     259                 :      10186 :         return ((*mpPolyPolygon) == (*rPolyPolygon.mpPolyPolygon));
     260                 :            :     }
     261                 :            : 
     262                 :        924 :     bool B3DPolyPolygon::operator!=(const B3DPolyPolygon& rPolyPolygon) const
     263                 :            :     {
     264                 :        924 :         return !(*this == rPolyPolygon);
     265                 :            :     }
     266                 :            : 
     267                 :     104821 :     sal_uInt32 B3DPolyPolygon::count() const
     268                 :            :     {
     269                 :     104821 :         return mpPolyPolygon->count();
     270                 :            :     }
     271                 :            : 
     272                 :      66355 :     B3DPolygon B3DPolyPolygon::getB3DPolygon(sal_uInt32 nIndex) const
     273                 :            :     {
     274                 :            :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
     275                 :            : 
     276                 :      66355 :         return mpPolyPolygon->getB3DPolygon(nIndex);
     277                 :            :     }
     278                 :            : 
     279                 :       9479 :     void B3DPolyPolygon::setB3DPolygon(sal_uInt32 nIndex, const B3DPolygon& rPolygon)
     280                 :            :     {
     281                 :            :         OSL_ENSURE(nIndex < mpPolyPolygon->count(), "B3DPolyPolygon access outside range (!)");
     282                 :            : 
     283 [ +  - ][ +  - ]:       9479 :         if(getB3DPolygon(nIndex) != rPolygon)
     284                 :       9479 :             mpPolyPolygon->setB3DPolygon(nIndex, rPolygon);
     285                 :       9479 :     }
     286                 :            : 
     287                 :        487 :     bool B3DPolyPolygon::areBColorsUsed() const
     288                 :            :     {
     289         [ +  + ]:        974 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     290                 :            :         {
     291         [ -  + ]:        487 :             if((mpPolyPolygon->getB3DPolygon(a)).areBColorsUsed())
     292                 :            :             {
     293                 :          0 :                 return true;
     294                 :            :             }
     295                 :            :         }
     296                 :            : 
     297                 :        487 :         return false;
     298                 :            :     }
     299                 :            : 
     300                 :        487 :     void B3DPolyPolygon::clearBColors()
     301                 :            :     {
     302         [ -  + ]:        487 :         if(areBColorsUsed())
     303                 :          0 :             mpPolyPolygon->clearBColors();
     304                 :        487 :     }
     305                 :            : 
     306                 :        224 :     void B3DPolyPolygon::transformNormals(const B3DHomMatrix& rMatrix)
     307                 :            :     {
     308         [ +  + ]:        224 :         if(!rMatrix.isIdentity())
     309                 :         66 :             mpPolyPolygon->transformNormals(rMatrix);
     310                 :        224 :     }
     311                 :            : 
     312                 :       1824 :     bool B3DPolyPolygon::areNormalsUsed() const
     313                 :            :     {
     314         [ +  + ]:       3063 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     315                 :            :         {
     316         [ +  + ]:       1824 :             if((mpPolyPolygon->getB3DPolygon(a)).areNormalsUsed())
     317                 :            :             {
     318                 :        585 :                 return true;
     319                 :            :             }
     320                 :            :         }
     321                 :            : 
     322                 :       1824 :         return false;
     323                 :            :     }
     324                 :            : 
     325                 :        770 :     void B3DPolyPolygon::clearNormals()
     326                 :            :     {
     327         [ +  + ]:        770 :         if(areNormalsUsed())
     328                 :        283 :             mpPolyPolygon->clearNormals();
     329                 :        770 :     }
     330                 :            : 
     331                 :        409 :     void B3DPolyPolygon::transformTextureCoordiantes(const B2DHomMatrix& rMatrix)
     332                 :            :     {
     333         [ +  - ]:        409 :         if(!rMatrix.isIdentity())
     334                 :        409 :             mpPolyPolygon->transformTextureCoordiantes(rMatrix);
     335                 :        409 :     }
     336                 :            : 
     337                 :       1184 :     bool B3DPolyPolygon::areTextureCoordinatesUsed() const
     338                 :            :     {
     339         [ +  - ]:       1184 :         for(sal_uInt32 a(0L); a < mpPolyPolygon->count(); a++)
     340                 :            :         {
     341         [ +  - ]:       1184 :             if((mpPolyPolygon->getB3DPolygon(a)).areTextureCoordinatesUsed())
     342                 :            :             {
     343                 :       1184 :                 return true;
     344                 :            :             }
     345                 :            :         }
     346                 :            : 
     347                 :       1184 :         return false;
     348                 :            :     }
     349                 :            : 
     350                 :        505 :     void B3DPolyPolygon::clearTextureCoordinates()
     351                 :            :     {
     352         [ +  - ]:        505 :         if(areTextureCoordinatesUsed())
     353                 :        505 :             mpPolyPolygon->clearTextureCoordinates();
     354                 :        505 :     }
     355                 :            : 
     356                 :      15795 :     void B3DPolyPolygon::append(const B3DPolygon& rPolygon, sal_uInt32 nCount)
     357                 :            :     {
     358         [ +  - ]:      15795 :         if(nCount)
     359                 :      15795 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolygon, nCount);
     360                 :      15795 :     }
     361                 :            : 
     362                 :          0 :     void B3DPolyPolygon::append(const B3DPolyPolygon& rPolyPolygon)
     363                 :            :     {
     364         [ #  # ]:          0 :         if(rPolyPolygon.count())
     365                 :          0 :             mpPolyPolygon->insert(mpPolyPolygon->count(), rPolyPolygon);
     366                 :          0 :     }
     367                 :            : 
     368                 :          0 :     void B3DPolyPolygon::remove(sal_uInt32 nIndex, sal_uInt32 nCount)
     369                 :            :     {
     370                 :            :         OSL_ENSURE(nIndex + nCount <= mpPolyPolygon->count(), "B3DPolyPolygon Remove outside range (!)");
     371                 :            : 
     372         [ #  # ]:          0 :         if(nCount)
     373                 :          0 :             mpPolyPolygon->remove(nIndex, nCount);
     374                 :          0 :     }
     375                 :            : 
     376                 :          0 :     void B3DPolyPolygon::clear()
     377                 :            :     {
     378                 :          0 :         mpPolyPolygon = DefaultPolyPolygon::get();
     379                 :          0 :     }
     380                 :            : 
     381                 :      10158 :     void B3DPolyPolygon::flip()
     382                 :            :     {
     383                 :      10158 :         mpPolyPolygon->flip();
     384                 :      10158 :     }
     385                 :            : 
     386                 :          0 :     bool B3DPolyPolygon::hasDoublePoints() const
     387                 :            :     {
     388                 :          0 :         bool bRetval(false);
     389                 :            : 
     390 [ #  # ][ #  # ]:          0 :         for(sal_uInt32 a(0L); !bRetval && a < mpPolyPolygon->count(); a++)
                 [ #  # ]
     391                 :            :         {
     392         [ #  # ]:          0 :             if((mpPolyPolygon->getB3DPolygon(a)).hasDoublePoints())
     393                 :            :             {
     394                 :          0 :                 bRetval = true;
     395                 :            :             }
     396                 :            :         }
     397                 :            : 
     398                 :          0 :         return bRetval;
     399                 :            :     }
     400                 :            : 
     401                 :          0 :     void B3DPolyPolygon::removeDoublePoints()
     402                 :            :     {
     403         [ #  # ]:          0 :         if(hasDoublePoints())
     404                 :          0 :             mpPolyPolygon->removeDoublePoints();
     405                 :          0 :     }
     406                 :            : 
     407                 :      13092 :     void B3DPolyPolygon::transform(const B3DHomMatrix& rMatrix)
     408                 :            :     {
     409 [ +  - ][ +  + ]:      13092 :         if(mpPolyPolygon->count() && !rMatrix.isIdentity())
                 [ +  + ]
     410                 :            :         {
     411                 :       8150 :             mpPolyPolygon->transform(rMatrix);
     412                 :            :         }
     413                 :      13092 :     }
     414                 :            : 
     415                 :          0 :     const B3DPolygon* B3DPolyPolygon::begin() const
     416                 :            :     {
     417                 :          0 :         return mpPolyPolygon->begin();
     418                 :            :     }
     419                 :            : 
     420                 :          0 :     const B3DPolygon* B3DPolyPolygon::end() const
     421                 :            :     {
     422                 :          0 :         return mpPolyPolygon->end();
     423                 :            :     }
     424                 :            : 
     425                 :          0 :     B3DPolygon* B3DPolyPolygon::begin()
     426                 :            :     {
     427                 :          0 :         return mpPolyPolygon->begin();
     428                 :            :     }
     429                 :            : 
     430                 :          0 :     B3DPolygon* B3DPolyPolygon::end()
     431                 :            :     {
     432                 :          0 :         return mpPolyPolygon->end();
     433                 :            :     }
     434                 :            : } // end of namespace basegfx
     435                 :            : 
     436                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10