LCOV - code coverage report
Current view: top level - sw/source/core/bastyp - swrect.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 115 142 81.0 %
Date: 2014-04-11 Functions: 42 51 82.4 %
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 "swrect.hxx"
      21             : 
      22             : #ifdef DBG_UTIL
      23             : #include <tools/stream.hxx>
      24             : #endif
      25             : 
      26             : #include <math.h>
      27             : #include <stdlib.h>
      28             : 
      29      814095 : SwRect::SwRect( const Rectangle &rRect ) :
      30      814095 :     m_Point( rRect.Left(), rRect.Top() )
      31             : {
      32      814095 :     m_Size.setWidth(rRect.Right() == RECT_EMPTY ? 0 :
      33      814095 :                             rRect.Right()  - rRect.Left() +1);
      34      814095 :     m_Size.setHeight(rRect.Bottom() == RECT_EMPTY ? 0 :
      35      814095 :                             rRect.Bottom() - rRect.Top() + 1);
      36      814095 : }
      37             : 
      38       64190 : Point SwRect::Center() const
      39             : {
      40       64190 :     return Point( Left() + Width()  / 2,
      41      128380 :                   Top()  + Height() / 2 );
      42             : }
      43             : 
      44       12696 : SwRect& SwRect::Union( const SwRect& rRect )
      45             : {
      46       12696 :     if ( Top() > rRect.Top() )
      47        1167 :         Top( rRect.Top() );
      48       12696 :     if ( Left() > rRect.Left() )
      49         725 :         Left( rRect.Left() );
      50       12696 :     long n = rRect.Right();
      51       12696 :     if ( Right() < n )
      52        3471 :         Right( n );
      53       12696 :     n = rRect.Bottom();
      54       12696 :     if ( Bottom() < n )
      55        9454 :         Bottom( n );
      56       12696 :     return *this;
      57             : }
      58             : 
      59       36266 : SwRect& SwRect::Intersection( const SwRect& rRect )
      60             : {
      61             :     // any similarity between me and given element?
      62       36266 :     if ( IsOver( rRect ) )
      63             :     {
      64             :         // get smaller right and lower, and greater left and upper edge
      65       27649 :         if ( Left() < rRect.Left() )
      66        1124 :             Left( rRect.Left() );
      67       27649 :         if ( Top() < rRect.Top() )
      68        5132 :             Top( rRect.Top() );
      69       27649 :         long n = rRect.Right();
      70       27649 :         if ( Right() > n )
      71        6628 :             Right( n );
      72       27649 :         n = rRect.Bottom();
      73       27649 :         if ( Bottom() > n )
      74        7980 :             Bottom( n );
      75             :     }
      76             :     else
      77             :         // Def.: if intersection is empty, set only SSize to 0
      78        8617 :         SSize(0, 0);
      79             : 
      80       36266 :     return *this;
      81             : }
      82             : 
      83      103452 : SwRect& SwRect::_Intersection( const SwRect& rRect )
      84             : {
      85             :     // get smaller right and lower, and greater left and upper edge
      86      103452 :     if ( Left() < rRect.Left() )
      87       49784 :         Left( rRect.Left() );
      88      103452 :     if ( Top() < rRect.Top() )
      89       46076 :         Top( rRect.Top() );
      90      103452 :     long n = rRect.Right();
      91      103452 :     if ( Right() > n )
      92       65050 :         Right( n );
      93      103452 :     n = rRect.Bottom();
      94      103452 :     if ( Bottom() > n )
      95       51345 :         Bottom( n );
      96             : 
      97      103452 :     return *this;
      98             : }
      99             : 
     100       55147 : sal_Bool SwRect::IsInside( const SwRect& rRect ) const
     101             : {
     102       55147 :     const long nRight  = Right();
     103       55147 :     const long nBottom = Bottom();
     104       55147 :     const long nrRight = rRect.Right();
     105       55147 :     const long nrBottom= rRect.Bottom();
     106      136951 :     return (Left() <= rRect.Left()) && (rRect.Left()<= nRight)  &&
     107      112130 :            (Left() <= nrRight)      && (nrRight     <= nRight)  &&
     108       90477 :            (Top()  <= rRect.Top())  && (rRect.Top() <= nBottom) &&
     109      105861 :            (Top()  <= nrBottom)     && (nrBottom    <= nBottom);
     110             : }
     111             : 
     112      153180 : sal_Bool SwRect::IsInside( const Point& rPoint ) const
     113             : {
     114      257124 :     return (Left()  <= rPoint.X()) &&
     115      207085 :            (Top()   <= rPoint.Y()) &&
     116      359190 :            (Right() >= rPoint.X()) &&
     117      256049 :            (Bottom()>= rPoint.Y());
     118             : }
     119             : 
     120             : // mouse moving of table borders
     121           0 : sal_Bool SwRect::IsNear( const Point& rPoint, long nTolerance ) const
     122             : {
     123           0 :     bool bIsNearby = (((Left()   - nTolerance) <= rPoint.X()) &&
     124           0 :                       ((Top()    - nTolerance) <= rPoint.Y()) &&
     125           0 :                       ((Right()  + nTolerance) >= rPoint.X()) &&
     126           0 :                       ((Bottom() + nTolerance) >= rPoint.Y()));
     127           0 :     return IsInside(rPoint) || bIsNearby;
     128             : }
     129             : 
     130      621121 : sal_Bool SwRect::IsOver( const SwRect& rRect ) const
     131             : {
     132     1082778 :     return (Top()   <= rRect.Bottom()) &&
     133      900749 :            (Left()  <= rRect.Right())  &&
     134     1436590 :            (Right() >= rRect.Left())   &&
     135      997498 :            (Bottom()>= rRect.Top());
     136             : }
     137             : 
     138         144 : void SwRect::Justify()
     139             : {
     140         144 :     if ( m_Size.getHeight() < 0 )
     141             :     {
     142           0 :         m_Point.setY(m_Point.getY() + m_Size.getHeight() + 1);
     143           0 :         m_Size.setHeight(-m_Size.getHeight());
     144             :     }
     145         144 :     if ( m_Size.getWidth() < 0 )
     146             :     {
     147           0 :         m_Point.setX(m_Point.getX() + m_Size.getWidth() + 1);
     148           0 :         m_Size.setWidth(-m_Size.getWidth());
     149             :     }
     150         144 : }
     151             : 
     152             : // Similar to the inline methods, but we need the function pointers
     153       79971 : void SwRect::_Width( const long nNew ) { m_Size.setWidth(nNew); }
     154      188554 : void SwRect::_Height( const long nNew ) { m_Size.setHeight(nNew); }
     155      102900 : void SwRect::_Left( const long nLeft ){ m_Size.Width() += m_Point.getX() - nLeft; m_Point.setX(nLeft); }
     156       96826 : void SwRect::_Right( const long nRight ){ m_Size.setWidth(nRight - m_Point.getX()); }
     157       31150 : void SwRect::_Top( const long nTop ){ m_Size.Height() += m_Point.getY() - nTop; m_Point.setY(nTop); }
     158        2103 : void SwRect::_Bottom( const long nBottom ){ m_Size.setHeight(nBottom - m_Point.getY()); }
     159             : 
     160     1111337 : long SwRect::_Width() const{ return m_Size.getWidth(); }
     161     2312122 : long SwRect::_Height() const{ return m_Size.getHeight(); }
     162     1698931 : long SwRect::_Left() const{ return m_Point.getX(); }
     163      564234 : long SwRect::_Right() const{ return m_Point.getX() + m_Size.getWidth(); }
     164     1229535 : long SwRect::_Top() const{ return m_Point.getY(); }
     165      206240 : long SwRect::_Bottom() const{ return m_Point.getY() + m_Size.getHeight(); }
     166             : 
     167         140 : void SwRect::AddWidth( const long nAdd ) { m_Size.Width() += nAdd; }
     168           0 : void SwRect::AddHeight( const long nAdd ) { m_Size.Height() += nAdd; }
     169       16227 : void SwRect::SubLeft( const long nSub ){ m_Size.Width() += nSub; m_Point.setX(m_Point.getX() - nSub); }
     170       63256 : void SwRect::AddRight( const long nAdd ){ m_Size.Width() += nAdd; }
     171       35102 : void SwRect::SubTop( const long nSub ){ m_Size.Height() += nSub; m_Point.setY(m_Point.getY() - nSub); }
     172       88980 : void SwRect::AddBottom( const long nAdd ){ m_Size.Height() += nAdd; }
     173       40290 : void SwRect::SetPosX( const long nNew ){ m_Point.setX(nNew); }
     174       58918 : void SwRect::SetPosY( const long nNew ){ m_Point.setY(nNew); }
     175             : 
     176           0 : const Size  SwRect::_Size() const { return SSize(); }
     177           0 : const Size  SwRect::SwappedSize() const { return Size( m_Size.getHeight(), m_Size.getWidth() ); }
     178             : 
     179      312477 : const Point SwRect::TopLeft() const { return Pos(); }
     180        6804 : const Point SwRect::TopRight() const { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() ); }
     181        6792 : const Point SwRect::BottomLeft() const { return Point( m_Point.getX(), m_Point.getY() + m_Size.getHeight() ); }
     182        6792 : const Point SwRect::BottomRight() const
     183        6792 :     { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() + m_Size.getHeight() ); }
     184             : 
     185       10586 : long SwRect::GetLeftDistance( long nLimit ) const { return m_Point.getX() - nLimit; }
     186      111220 : long SwRect::GetBottomDistance( long nLim ) const { return nLim - m_Point.getY() - m_Size.getHeight();}
     187       77967 : long SwRect::GetTopDistance( long nLimit ) const { return m_Point.getY() - nLimit; }
     188           1 : long SwRect::GetRightDistance( long nLim ) const { return nLim - m_Point.getX() - m_Size.getWidth(); }
     189             : 
     190       14334 : sal_Bool SwRect::OverStepLeft( long nLimit ) const
     191       14334 :     { return nLimit > m_Point.getX() && m_Point.getX() + m_Size.getWidth() > nLimit; }
     192       37949 : sal_Bool SwRect::OverStepBottom( long nLimit ) const
     193       37949 :     { return nLimit > m_Point.getY() && m_Point.getY() + m_Size.getHeight() > nLimit; }
     194           0 : sal_Bool SwRect::OverStepTop( long nLimit ) const
     195           0 :     { return nLimit > m_Point.getY() && m_Point.getY() + m_Size.getHeight() > nLimit; }
     196           0 : sal_Bool SwRect::OverStepRight( long nLimit ) const
     197           0 :     { return nLimit > m_Point.getX() && m_Point.getX() + m_Size.getWidth() > nLimit; }
     198             : 
     199         106 : void SwRect::SetLeftAndWidth( long nLeft, long nNew )
     200             : {
     201         106 :     m_Point.setX(nLeft);
     202         106 :     m_Size.setWidth(nNew);
     203         106 : }
     204       35170 : void SwRect::SetTopAndHeight( long nTop, long nNew )
     205             : {
     206       35170 :     m_Point.setY(nTop);
     207       35170 :     m_Size.setHeight(nNew);
     208       35170 : }
     209           0 : void SwRect::SetRightAndWidth( long nRight, long nNew )
     210             : {
     211           0 :     m_Point.setX(nRight - nNew);
     212           0 :     m_Size.setWidth(nNew);
     213           0 : }
     214           0 : void SwRect::SetBottomAndHeight( long nBottom, long nNew )
     215             : {
     216           0 :     m_Point.setY(nBottom - nNew);
     217           0 :     m_Size.setHeight(nNew);
     218           0 : }
     219       26007 : void SwRect::SetUpperLeftCorner(  const Point& rNew )
     220       26007 :     { m_Point = rNew; }
     221           1 : void SwRect::SetUpperRightCorner(  const Point& rNew )
     222           1 :     { m_Point = Point(rNew.A() - m_Size.getWidth(), rNew.B()); }
     223           0 : void SwRect::SetLowerLeftCorner(  const Point& rNew )
     224           0 :     { m_Point = Point(rNew.A(), rNew.B() - m_Size.getHeight()); }
     225             : 
     226             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10