LCOV - code coverage report
Current view: top level - tools/source/generic - gen.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 88 92 95.7 %
Date: 2012-08-25 Functions: 11 11 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 69 104 66.3 %

           Branch data     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 <tools/debug.hxx>
      21                 :            : #include <tools/gen.hxx>
      22                 :            : #include <tools/stream.hxx>
      23                 :            : 
      24                 :     197466 : SvStream& operator>>( SvStream& rIStream, Pair& rPair )
      25                 :            : {
      26                 :            :     DBG_ASSERTWARNING( rIStream.GetVersion(), "Pair::>> - Solar-Version not set on rIStream" );
      27                 :            : 
      28                 :            :     //39428 SvStream no longer supports operator>>(long&)
      29                 :     197466 :     sal_Int32 nTmpA(0), nTmpB(0);
      30 [ +  - ][ +  - ]:     197466 :     rIStream >> nTmpA >> nTmpB;
      31                 :     197466 :     rPair.nA = nTmpA;
      32                 :     197466 :     rPair.nB = nTmpB;
      33                 :            : 
      34                 :     197466 :     return rIStream;
      35                 :            : }
      36                 :            : 
      37                 :     222310 : SvStream& operator<<( SvStream& rOStream, const Pair& rPair )
      38                 :            : {
      39                 :            :     DBG_ASSERTWARNING( rOStream.GetVersion(), "Pair::<< - Solar-Version not set on rOStream" );
      40                 :            : 
      41                 :            :     //39428 SvStream no longer supports operator<<(long)
      42                 :     222310 :     rOStream << sal::static_int_cast<sal_Int32>(rPair.nA) << sal::static_int_cast<sal_Int32>(rPair.nB);
      43                 :            : 
      44                 :     222310 :     return rOStream;
      45                 :            : }
      46                 :            : 
      47                 :     241721 : void Rectangle::SetSize( const Size& rSize )
      48                 :            : {
      49         [ +  + ]:     241721 :     if ( rSize.Width() < 0 )
      50                 :        376 :         nRight  = nLeft + rSize.Width() +1;
      51         [ +  + ]:     241345 :     else if ( rSize.Width() > 0 )
      52                 :     236606 :         nRight  = nLeft + rSize.Width() -1;
      53                 :            :     else
      54                 :       4739 :         nRight = RECT_EMPTY;
      55                 :            : 
      56         [ +  + ]:     241721 :     if ( rSize.Height() < 0 )
      57                 :        385 :         nBottom  = nTop + rSize.Height() +1;
      58         [ +  + ]:     241336 :     else if ( rSize.Height() > 0 )
      59                 :     239959 :         nBottom  = nTop + rSize.Height() -1;
      60                 :            :     else
      61                 :       1377 :         nBottom = RECT_EMPTY;
      62                 :     241721 : }
      63                 :            : 
      64                 :     554360 : Rectangle& Rectangle::Union( const Rectangle& rRect )
      65                 :            : {
      66         [ +  + ]:     554360 :     if ( rRect.IsEmpty() )
      67                 :     168931 :         return *this;
      68                 :            : 
      69         [ +  + ]:     385429 :     if ( IsEmpty() )
      70                 :      52041 :         *this = rRect;
      71                 :            :     else
      72                 :            :     {
      73                 :     333388 :         nLeft  =  Min( Min( nLeft, rRect.nLeft ), Min( nRight, rRect.nRight )   );
      74                 :     333388 :         nRight  = Max( Max( nLeft, rRect.nLeft ), Max( nRight, rRect.nRight )   );
      75                 :     333388 :         nTop    = Min( Min( nTop, rRect.nTop ),   Min( nBottom, rRect.nBottom ) );
      76                 :     333388 :         nBottom = Max( Max( nTop, rRect.nTop ),   Max( nBottom, rRect.nBottom ) );
      77                 :            :     }
      78                 :            : 
      79                 :     554360 :     return *this;
      80                 :            : }
      81                 :            : 
      82                 :    1302251 : Rectangle& Rectangle::Intersection( const Rectangle& rRect )
      83                 :            : {
      84 [ +  - ][ +  + ]:    1302251 :     if ( IsEmpty() )
      85                 :      33160 :         return *this;
      86 [ +  - ][ +  + ]:    1269091 :     if ( rRect.IsEmpty() )
      87                 :            :     {
      88         [ +  - ]:      11273 :         *this = Rectangle();
      89                 :      11273 :         return *this;
      90                 :            :     }
      91                 :            : 
      92                 :            :     // Justify rectangle
      93                 :    1257818 :     Rectangle aTmpRect( rRect );
      94         [ +  - ]:    1257818 :     Justify();
      95         [ +  - ]:    1257818 :     aTmpRect.Justify();
      96                 :            : 
      97                 :            :     // Perform intersection
      98                 :    1257818 :     nLeft  = Max( nLeft, aTmpRect.nLeft );
      99                 :    1257818 :     nRight = Min( nRight, aTmpRect.nRight );
     100                 :    1257818 :     nTop   = Max( nTop, aTmpRect.nTop );
     101                 :    1257818 :     nBottom= Min( nBottom, aTmpRect.nBottom );
     102                 :            : 
     103                 :            :     // Determine if intersection is empty
     104 [ +  + ][ +  + ]:    1257818 :     if ( nRight < nLeft || nBottom < nTop )
     105         [ +  - ]:     386249 :         *this = Rectangle();
     106                 :            : 
     107                 :    1302251 :     return *this;
     108                 :            : }
     109                 :            : 
     110                 :    3739709 : void Rectangle::Justify()
     111                 :            : {
     112                 :            :     long nHelp;
     113                 :            : 
     114 [ +  + ][ +  + ]:    3739709 :     if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
     115                 :            :     {
     116                 :        338 :         nHelp = nLeft;
     117                 :        338 :         nLeft = nRight;
     118                 :        338 :         nRight = nHelp;
     119                 :            :     }
     120                 :            : 
     121 [ +  + ][ +  + ]:    3739709 :     if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
     122                 :            :     {
     123                 :       1346 :         nHelp = nBottom;
     124                 :       1346 :         nBottom = nTop;
     125                 :       1346 :         nTop = nHelp;
     126                 :            :     }
     127                 :    3739709 : }
     128                 :            : 
     129                 :     120115 : sal_Bool Rectangle::IsInside( const Point& rPoint ) const
     130                 :            : {
     131         [ +  + ]:     120115 :     if ( IsEmpty() )
     132                 :      13597 :         return sal_False;
     133                 :            : 
     134                 :     106518 :     sal_Bool bRet = sal_True;
     135         [ +  - ]:     106518 :     if ( nLeft <= nRight )
     136                 :            :     {
     137 [ +  + ][ +  + ]:     106518 :         if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
                 [ +  + ]
     138                 :       6775 :             bRet = sal_False;
     139                 :            :     }
     140                 :            :     else
     141                 :            :     {
     142 [ #  # ][ #  # ]:          0 :         if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
                 [ #  # ]
     143                 :          0 :             bRet = sal_False;
     144                 :            :     }
     145         [ +  - ]:     106518 :     if ( nTop <= nBottom )
     146                 :            :     {
     147 [ +  + ][ +  + ]:     106518 :         if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
                 [ +  + ]
     148                 :       9739 :             bRet = sal_False;
     149                 :            :     }
     150                 :            :     else
     151                 :            :     {
     152 [ #  # ][ #  # ]:          0 :         if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
                 [ #  # ]
     153                 :          0 :             bRet = sal_False;
     154                 :            :     }
     155                 :     120115 :     return bRet;
     156                 :            : }
     157                 :            : 
     158                 :      49464 : sal_Bool Rectangle::IsInside( const Rectangle& rRect ) const
     159                 :            : {
     160 [ +  - ][ +  + ]:      49464 :     if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
         [ +  - ][ +  - ]
         [ +  + ][ +  + ]
         [ +  - ][ +  +  
             #  #  #  # ]
     161                 :      47619 :         return sal_True;
     162                 :            :     else
     163                 :      49464 :         return sal_False;
     164                 :            : }
     165                 :            : 
     166                 :     640754 : sal_Bool Rectangle::IsOver( const Rectangle& rRect ) const
     167                 :            : {
     168                 :            :     // If there's no intersection, they don't overlap
     169         [ +  - ]:     640754 :     return !GetIntersection( rRect ).IsEmpty();
     170                 :            : }
     171                 :            : 
     172                 :      19342 : SvStream& operator>>( SvStream& rIStream, Rectangle& rRect )
     173                 :            : {
     174                 :            :     DBG_ASSERTWARNING( rIStream.GetVersion(), "Rectangle::>> - Solar-Version not set on rIStream" );
     175                 :            : 
     176                 :            :     //fdo#39428 SvStream no longer supports operator>>(long&)
     177                 :      19342 :     sal_Int32 nTmpL(0), nTmpT(0), nTmpR(0), nTmpB(0);
     178                 :            : 
     179 [ +  - ][ +  - ]:      19342 :     rIStream >> nTmpL >> nTmpT >> nTmpR >> nTmpB;
         [ +  - ][ +  - ]
     180                 :            : 
     181                 :      19342 :     rRect.nLeft = nTmpL;
     182                 :      19342 :     rRect.nTop = nTmpT;
     183                 :      19342 :     rRect.nRight = nTmpR;
     184                 :      19342 :     rRect.nBottom = nTmpB;
     185                 :            : 
     186                 :      19342 :     return rIStream;
     187                 :            : }
     188                 :            : 
     189                 :      29879 : SvStream& operator<<( SvStream& rOStream, const Rectangle& rRect )
     190                 :            : {
     191                 :            :     DBG_ASSERTWARNING( rOStream.GetVersion(), "Rectangle::<< - Solar-Version not set on rOStream" );
     192                 :            : 
     193                 :            :     //fdo#39428 SvStream no longer supports operator<<(long)
     194                 :      29879 :     rOStream << sal::static_int_cast<sal_Int32>(rRect.nLeft)
     195                 :      59758 :              << sal::static_int_cast<sal_Int32>(rRect.nTop)
     196                 :      59758 :              << sal::static_int_cast<sal_Int32>(rRect.nRight)
     197                 :      59758 :              << sal::static_int_cast<sal_Int32>(rRect.nBottom);
     198                 :            : 
     199                 :      29879 :     return rOStream;
     200                 :            : }
     201                 :            : 
     202                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10