LCOV - code coverage report
Current view: top level - basegfx/source/range - b2dpolyrange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 62 83.9 %
Date: 2012-08-25 Functions: 21 24 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 10 34 29.4 %

           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 2008 by Sun Microsystems, Inc.
       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 <basegfx/range/b2dpolyrange.hxx>
      30                 :            : 
      31                 :            : #include <basegfx/range/b2drange.hxx>
      32                 :            : #include <basegfx/range/b2drangeclipper.hxx>
      33                 :            : #include <basegfx/tuple/b2dtuple.hxx>
      34                 :            : #include <basegfx/polygon/b2dpolypolygon.hxx>
      35                 :            : 
      36                 :            : #include <boost/bind.hpp>
      37                 :            : #include <boost/tuple/tuple.hpp>
      38                 :            : #include <algorithm>
      39                 :            : #include <vector>
      40                 :            : 
      41                 :            : namespace basegfx
      42                 :            : {
      43         [ +  - ]:        919 :     class ImplB2DPolyRange
      44                 :            :     {
      45                 :            :         void updateBounds()
      46                 :            :         {
      47                 :            :             maBounds.reset();
      48                 :            :             std::for_each(maRanges.begin(),
      49                 :            :                           maRanges.end(),
      50                 :            :                           boost::bind(
      51                 :            :                               (void (B2DRange::*)(const B2DRange&))(
      52                 :            :                  &B2DRange::expand),
      53                 :            :                               boost::ref(maBounds),
      54                 :            :                               _1));
      55                 :            :         }
      56                 :            : 
      57                 :            :     public:
      58                 :        829 :         ImplB2DPolyRange() :
      59                 :            :             maBounds(),
      60                 :            :             maRanges(),
      61         [ +  - ]:        829 :             maOrient()
      62                 :        829 :         {}
      63                 :            : 
      64                 :            :         explicit ImplB2DPolyRange( const B2DRange& rRange, B2VectorOrientation eOrient ) :
      65                 :            :             maBounds( rRange ),
      66                 :            :             maRanges( 1, rRange ),
      67                 :            :             maOrient( 1, eOrient )
      68                 :            :         {}
      69                 :            : 
      70                 :         15 :         bool operator==(const ImplB2DPolyRange& rRHS) const
      71                 :            :         {
      72 [ +  - ][ +  - ]:         15 :             return maRanges == rRHS.maRanges && maOrient == rRHS.maOrient;
      73                 :            :         }
      74                 :            : 
      75                 :        457 :         sal_uInt32 count() const
      76                 :            :         {
      77                 :        457 :             return maRanges.size();
      78                 :            :         }
      79                 :            : 
      80                 :        210 :         B2DPolyRange::ElementType getElement(sal_uInt32 nIndex) const
      81                 :            :         {
      82                 :        210 :             return boost::make_tuple(maRanges[nIndex],
      83                 :        420 :                                      maOrient[nIndex]);
      84                 :            :         }
      85                 :            : 
      86                 :       1530 :         void appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
      87                 :            :         {
      88                 :       1530 :             maRanges.insert(maRanges.end(), nCount, rRange);
      89                 :       1530 :             maOrient.insert(maOrient.end(), nCount, eOrient);
      90                 :       1530 :             maBounds.expand(rRange);
      91                 :       1530 :         }
      92                 :            : 
      93                 :         75 :         void clear()
      94                 :            :         {
      95         [ +  - ]:         75 :             std::vector<B2DRange> aTmpRanges;
      96         [ +  - ]:         75 :             std::vector<B2VectorOrientation> aTmpOrient;
      97                 :            : 
      98                 :         75 :             maRanges.swap(aTmpRanges);
      99                 :         75 :             maOrient.swap(aTmpOrient);
     100                 :            : 
     101         [ +  - ]:         75 :             maBounds.reset();
     102                 :         75 :         }
     103                 :            : 
     104                 :          0 :         bool overlaps( const B2DRange& rRange ) const
     105                 :            :         {
     106 [ #  # ][ #  # ]:          0 :             if( !maBounds.overlaps( rRange ) )
     107                 :          0 :                 return false;
     108                 :            : 
     109                 :          0 :             const std::vector<B2DRange>::const_iterator aEnd( maRanges.end() );
     110                 :            :             return std::find_if( maRanges.begin(),
     111                 :            :                                  aEnd,
     112                 :            :                                  boost::bind<bool>( boost::mem_fn( &B2DRange::overlaps ),
     113                 :            :                                                     _1,
     114 [ #  # ][ #  # ]:          0 :                                                     boost::cref(rRange) ) ) != aEnd;
         [ #  # ][ #  # ]
                 [ #  # ]
     115                 :            :         }
     116                 :            : 
     117                 :        255 :         B2DPolyPolygon solveCrossovers() const
     118                 :            :         {
     119                 :        255 :             return tools::solveCrossovers(maRanges,maOrient);
     120                 :            :         }
     121                 :            : 
     122                 :            :     private:
     123                 :            :         B2DRange                         maBounds;
     124                 :            :         std::vector<B2DRange>            maRanges;
     125                 :            :         std::vector<B2VectorOrientation> maOrient;
     126                 :            :     };
     127                 :            : 
     128                 :        829 :     B2DPolyRange::B2DPolyRange() :
     129                 :        829 :         mpImpl()
     130                 :        829 :     {}
     131                 :            : 
     132                 :        859 :     B2DPolyRange::~B2DPolyRange()
     133                 :        859 :     {}
     134                 :            : 
     135                 :         30 :     B2DPolyRange::B2DPolyRange( const B2DPolyRange& rRange ) :
     136                 :         30 :         mpImpl( rRange.mpImpl )
     137                 :         30 :     {}
     138                 :            : 
     139                 :         30 :     B2DPolyRange& B2DPolyRange::operator=( const B2DPolyRange& rRange )
     140                 :            :     {
     141                 :         30 :         mpImpl = rRange.mpImpl;
     142                 :         30 :         return *this;
     143                 :            :     }
     144                 :            : 
     145                 :         15 :     bool B2DPolyRange::operator==(const B2DPolyRange& rRange) const
     146                 :            :     {
     147         [ -  + ]:         15 :         if(mpImpl.same_object(rRange.mpImpl))
     148                 :          0 :             return true;
     149                 :            : 
     150                 :         15 :         return ((*mpImpl) == (*rRange.mpImpl));
     151                 :            :     }
     152                 :            : 
     153                 :          0 :     bool B2DPolyRange::operator!=(const B2DPolyRange& rRange) const
     154                 :            :     {
     155                 :          0 :         return !(*this == rRange);
     156                 :            :     }
     157                 :            : 
     158                 :        457 :     sal_uInt32 B2DPolyRange::count() const
     159                 :            :     {
     160                 :        457 :         return mpImpl->count();
     161                 :            :     }
     162                 :            : 
     163                 :        210 :     B2DPolyRange::ElementType B2DPolyRange::getElement(sal_uInt32 nIndex) const
     164                 :            :     {
     165                 :        210 :         return mpImpl->getElement(nIndex);
     166                 :            :     }
     167                 :            : 
     168                 :       1530 :     void B2DPolyRange::appendElement(const B2DRange& rRange, B2VectorOrientation eOrient, sal_uInt32 nCount)
     169                 :            :     {
     170                 :       1530 :         mpImpl->appendElement(rRange, eOrient, nCount );
     171                 :       1530 :     }
     172                 :            : 
     173                 :         75 :     void B2DPolyRange::clear()
     174                 :            :     {
     175                 :         75 :         mpImpl->clear();
     176                 :         75 :     }
     177                 :            : 
     178                 :          0 :     bool B2DPolyRange::overlaps( const B2DRange& rRange ) const
     179                 :            :     {
     180                 :          0 :         return mpImpl->overlaps(rRange);
     181                 :            :     }
     182                 :            : 
     183                 :        255 :     B2DPolyPolygon B2DPolyRange::solveCrossovers() const
     184                 :            :     {
     185                 :        255 :         return mpImpl->solveCrossovers();
     186                 :            :     }
     187 [ +  - ][ +  - ]:       5523 : } // end of namespace basegfx
     188                 :            : 
     189                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10