LCOV - code coverage report
Current view: top level - tools/source/generic - gen.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 92 92 100.0 %
Date: 2014-04-11 Functions: 11 11 100.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 <tools/debug.hxx>
      21             : #include <tools/gen.hxx>
      22             : #include <tools/stream.hxx>
      23             : 
      24       87945 : SvStream& ReadPair( 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       87945 :     sal_Int32 nTmpA(0), nTmpB(0);
      30       87945 :     rIStream.ReadInt32( nTmpA ).ReadInt32( nTmpB );
      31       87945 :     rPair.nA = nTmpA;
      32       87945 :     rPair.nB = nTmpB;
      33             : 
      34       87945 :     return rIStream;
      35             : }
      36             : 
      37      102050 : SvStream& WritePair( 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      102050 :     rOStream.WriteInt32( sal::static_int_cast<sal_Int32>(rPair.nA) ).WriteInt32( sal::static_int_cast<sal_Int32>(rPair.nB) );
      43             : 
      44      102050 :     return rOStream;
      45             : }
      46             : 
      47      153692 : void Rectangle::SetSize( const Size& rSize )
      48             : {
      49      153692 :     if ( rSize.Width() < 0 )
      50         245 :         nRight  = nLeft + rSize.Width() +1;
      51      153447 :     else if ( rSize.Width() > 0 )
      52      150255 :         nRight  = nLeft + rSize.Width() -1;
      53             :     else
      54        3192 :         nRight = RECT_EMPTY;
      55             : 
      56      153692 :     if ( rSize.Height() < 0 )
      57         253 :         nBottom  = nTop + rSize.Height() +1;
      58      153439 :     else if ( rSize.Height() > 0 )
      59      152339 :         nBottom  = nTop + rSize.Height() -1;
      60             :     else
      61        1100 :         nBottom = RECT_EMPTY;
      62      153692 : }
      63             : 
      64      495885 : Rectangle& Rectangle::Union( const Rectangle& rRect )
      65             : {
      66      495885 :     if ( rRect.IsEmpty() )
      67      154069 :         return *this;
      68             : 
      69      341816 :     if ( IsEmpty() )
      70       39470 :         *this = rRect;
      71             :     else
      72             :     {
      73      302346 :         nLeft  =  std::min( std::min( nLeft, rRect.nLeft ), std::min( nRight, rRect.nRight )   );
      74      302346 :         nRight  = std::max( std::max( nLeft, rRect.nLeft ), std::max( nRight, rRect.nRight )   );
      75      302346 :         nTop    = std::min( std::min( nTop, rRect.nTop ),   std::min( nBottom, rRect.nBottom ) );
      76      302346 :         nBottom = std::max( std::max( nTop, rRect.nTop ),   std::max( nBottom, rRect.nBottom ) );
      77             :     }
      78             : 
      79      341816 :     return *this;
      80             : }
      81             : 
      82      698708 : Rectangle& Rectangle::Intersection( const Rectangle& rRect )
      83             : {
      84      698708 :     if ( IsEmpty() )
      85          53 :         return *this;
      86      698655 :     if ( rRect.IsEmpty() )
      87             :     {
      88        8224 :         *this = Rectangle();
      89        8224 :         return *this;
      90             :     }
      91             : 
      92             :     // Justify rectangle
      93      690431 :     Rectangle aTmpRect( rRect );
      94      690431 :     Justify();
      95      690431 :     aTmpRect.Justify();
      96             : 
      97             :     // Perform intersection
      98      690431 :     nLeft  = std::max( nLeft, aTmpRect.nLeft );
      99      690431 :     nRight = std::min( nRight, aTmpRect.nRight );
     100      690431 :     nTop   = std::max( nTop, aTmpRect.nTop );
     101      690431 :     nBottom= std::min( nBottom, aTmpRect.nBottom );
     102             : 
     103             :     // Determine if intersection is empty
     104      690431 :     if ( nRight < nLeft || nBottom < nTop )
     105      226668 :         *this = Rectangle();
     106             : 
     107      690431 :     return *this;
     108             : }
     109             : 
     110     2338826 : void Rectangle::Justify()
     111             : {
     112             :     long nHelp;
     113             : 
     114     2338826 :     if ( (nRight < nLeft) && (nRight != RECT_EMPTY) )
     115             :     {
     116         164 :         nHelp = nLeft;
     117         164 :         nLeft = nRight;
     118         164 :         nRight = nHelp;
     119             :     }
     120             : 
     121     2338826 :     if ( (nBottom < nTop) && (nBottom != RECT_EMPTY) )
     122             :     {
     123         776 :         nHelp = nBottom;
     124         776 :         nBottom = nTop;
     125         776 :         nTop = nHelp;
     126             :     }
     127     2338826 : }
     128             : 
     129       86011 : bool Rectangle::IsInside( const Point& rPoint ) const
     130             : {
     131       86011 :     if ( IsEmpty() )
     132       10893 :         return false;
     133             : 
     134       75118 :     bool bRet = true;
     135       75118 :     if ( nLeft <= nRight )
     136             :     {
     137       75082 :         if ( (rPoint.X() < nLeft) || (rPoint.X() > nRight) )
     138        9443 :             bRet = false;
     139             :     }
     140             :     else
     141             :     {
     142          36 :         if ( (rPoint.X() > nLeft) || (rPoint.X() < nRight) )
     143           3 :             bRet = false;
     144             :     }
     145       75118 :     if ( nTop <= nBottom )
     146             :     {
     147       75082 :         if ( (rPoint.Y() < nTop) || (rPoint.Y() > nBottom) )
     148       11235 :             bRet = false;
     149             :     }
     150             :     else
     151             :     {
     152          36 :         if ( (rPoint.Y() > nTop) || (rPoint.Y() < nBottom) )
     153           3 :             bRet = false;
     154             :     }
     155       75118 :     return bRet;
     156             : }
     157             : 
     158       32778 : bool Rectangle::IsInside( const Rectangle& rRect ) const
     159             : {
     160       32778 :     if ( IsInside( rRect.TopLeft() ) && IsInside( rRect.BottomRight() ) )
     161       31526 :         return true;
     162             :     else
     163        1252 :         return false;
     164             : }
     165             : 
     166      313304 : bool Rectangle::IsOver( const Rectangle& rRect ) const
     167             : {
     168             :     // If there's no intersection, they don't overlap
     169      313304 :     return !GetIntersection( rRect ).IsEmpty();
     170             : }
     171             : 
     172        6968 : SvStream& ReadRectangle( 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        6968 :     sal_Int32 nTmpL(0), nTmpT(0), nTmpR(0), nTmpB(0);
     178             : 
     179        6968 :     rIStream.ReadInt32( nTmpL ).ReadInt32( nTmpT ).ReadInt32( nTmpR ).ReadInt32( nTmpB );
     180             : 
     181        6968 :     rRect.nLeft = nTmpL;
     182        6968 :     rRect.nTop = nTmpT;
     183        6968 :     rRect.nRight = nTmpR;
     184        6968 :     rRect.nBottom = nTmpB;
     185             : 
     186        6968 :     return rIStream;
     187             : }
     188             : 
     189       11671 : SvStream& WriteRectangle( 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       11671 :     rOStream.WriteInt32( sal::static_int_cast<sal_Int32>(rRect.nLeft) )
     195       23342 :             .WriteInt32( sal::static_int_cast<sal_Int32>(rRect.nTop) )
     196       23342 :             .WriteInt32( sal::static_int_cast<sal_Int32>(rRect.nRight) )
     197       23342 :             .WriteInt32( sal::static_int_cast<sal_Int32>(rRect.nBottom) );
     198             : 
     199       11671 :     return rOStream;
     200             : }
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10