LCOV - code coverage report
Current view: top level - sw/source/core/bastyp - swrect.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 125 142 88.0 %
Date: 2015-06-13 12:38:46 Functions: 44 51 86.3 %
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     2222359 : SwRect::SwRect( const Rectangle &rRect ) :
      30     2222359 :     m_Point( rRect.Left(), rRect.Top() )
      31             : {
      32     2222359 :     m_Size.setWidth(rRect.Right() == RECT_EMPTY ? 0 :
      33     2222359 :                             rRect.Right()  - rRect.Left() +1);
      34     2222359 :     m_Size.setHeight(rRect.Bottom() == RECT_EMPTY ? 0 :
      35     2222359 :                             rRect.Bottom() - rRect.Top() + 1);
      36     2222359 : }
      37             : 
      38       86026 : Point SwRect::Center() const
      39             : {
      40       86026 :     return Point( Left() + Width()  / 2,
      41      172052 :                   Top()  + Height() / 2 );
      42             : }
      43             : 
      44       18891 : SwRect& SwRect::Union( const SwRect& rRect )
      45             : {
      46       18891 :     if ( Top() > rRect.Top() )
      47         842 :         Top( rRect.Top() );
      48       18891 :     if ( Left() > rRect.Left() )
      49         278 :         Left( rRect.Left() );
      50       18891 :     long n = rRect.Right();
      51       18891 :     if ( Right() < n )
      52        7508 :         Right( n );
      53       18891 :     n = rRect.Bottom();
      54       18891 :     if ( Bottom() < n )
      55       11223 :         Bottom( n );
      56       18891 :     return *this;
      57             : }
      58             : 
      59       46523 : SwRect& SwRect::Intersection( const SwRect& rRect )
      60             : {
      61             :     // any similarity between me and given element?
      62       46523 :     if ( IsOver( rRect ) )
      63             :     {
      64             :         // get smaller right and lower, and greater left and upper edge
      65       37816 :         if ( Left() < rRect.Left() )
      66        1744 :             Left( rRect.Left() );
      67       37816 :         if ( Top() < rRect.Top() )
      68        6828 :             Top( rRect.Top() );
      69       37816 :         long n = rRect.Right();
      70       37816 :         if ( Right() > n )
      71       13066 :             Right( n );
      72       37816 :         n = rRect.Bottom();
      73       37816 :         if ( Bottom() > n )
      74       10921 :             Bottom( n );
      75             :     }
      76             :     else
      77             :         // Def.: if intersection is empty, set only SSize to 0
      78        8707 :         SSize(0, 0);
      79             : 
      80       46523 :     return *this;
      81             : }
      82             : 
      83      137397 : SwRect& SwRect::_Intersection( const SwRect& rRect )
      84             : {
      85             :     // get smaller right and lower, and greater left and upper edge
      86      137397 :     if ( Left() < rRect.Left() )
      87       49239 :         Left( rRect.Left() );
      88      137397 :     if ( Top() < rRect.Top() )
      89       58484 :         Top( rRect.Top() );
      90      137397 :     long n = rRect.Right();
      91      137397 :     if ( Right() > n )
      92       85919 :         Right( n );
      93      137397 :     n = rRect.Bottom();
      94      137397 :     if ( Bottom() > n )
      95       69606 :         Bottom( n );
      96             : 
      97      137397 :     return *this;
      98             : }
      99             : 
     100       65542 : bool SwRect::IsInside( const SwRect& rRect ) const
     101             : {
     102       65542 :     const long nRight  = Right();
     103       65542 :     const long nBottom = Bottom();
     104       65542 :     const long nrRight = rRect.Right();
     105       65542 :     const long nrBottom= rRect.Bottom();
     106      174101 :     return (Left() <= rRect.Left()) && (rRect.Left()<= nRight)  &&
     107      151116 :            (Left() <= nrRight)      && (nrRight     <= nRight)  &&
     108      132642 :            (Top()  <= rRect.Top())  && (rRect.Top() <= nBottom) &&
     109      146100 :            (Top()  <= nrBottom)     && (nrBottom    <= nBottom);
     110             : }
     111             : 
     112      250114 : bool SwRect::IsInside( const Point& rPoint ) const
     113             : {
     114      429658 :     return (Left()  <= rPoint.X()) &&
     115      358035 :            (Top()   <= rPoint.Y()) &&
     116      606850 :            (Right() >= rPoint.X()) &&
     117      428359 :            (Bottom()>= rPoint.Y());
     118             : }
     119             : 
     120             : // mouse moving of table borders
     121           8 : bool SwRect::IsNear( const Point& rPoint, long nTolerance ) const
     122             : {
     123          16 :     bool bIsNearby = (((Left()   - nTolerance) <= rPoint.X()) &&
     124          16 :                       ((Top()    - nTolerance) <= rPoint.Y()) &&
     125          24 :                       ((Right()  + nTolerance) >= rPoint.X()) &&
     126          16 :                       ((Bottom() + nTolerance) >= rPoint.Y()));
     127           8 :     return IsInside(rPoint) || bIsNearby;
     128             : }
     129             : 
     130    54644233 : bool SwRect::IsOver( const SwRect& rRect ) const
     131             : {
     132   108776644 :     return (Top()   <= rRect.Bottom()) &&
     133   108228725 :            (Left()  <= rRect.Right())  &&
     134   162734569 :            (Right() >= rRect.Left())   &&
     135   108638255 :            (Bottom()>= rRect.Top());
     136             : }
     137             : 
     138         177 : void SwRect::Justify()
     139             : {
     140         177 :     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         177 :     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         177 : }
     151             : 
     152             : // Similar to the inline methods, but we need the function pointers
     153      124791 : void SwRect::_Width( const long nNew ) { m_Size.setWidth(nNew); }
     154      266936 : void SwRect::_Height( const long nNew ) { m_Size.setHeight(nNew); }
     155      158399 : void SwRect::_Left( const long nLeft ){ m_Size.Width() += m_Point.getX() - nLeft; m_Point.setX(nLeft); }
     156      142937 : void SwRect::_Right( const long nRight ){ m_Size.setWidth(nRight - m_Point.getX()); }
     157       38166 : void SwRect::_Top( const long nTop ){ m_Size.Height() += m_Point.getY() - nTop; m_Point.setY(nTop); }
     158        2357 : void SwRect::_Bottom( const long nBottom ){ m_Size.setHeight(nBottom - m_Point.getY()); }
     159             : 
     160     1566458 : long SwRect::_Width() const{ return m_Size.getWidth(); }
     161     3226068 : long SwRect::_Height() const{ return m_Size.getHeight(); }
     162     4346435 : long SwRect::_Left() const{ return m_Point.getX(); }
     163     1135311 : long SwRect::_Right() const{ return m_Point.getX() + m_Size.getWidth(); }
     164     1835131 : long SwRect::_Top() const{ return m_Point.getY(); }
     165      438208 : long SwRect::_Bottom() const{ return m_Point.getY() + m_Size.getHeight(); }
     166             : 
     167         162 : void SwRect::AddWidth( const long nAdd ) { m_Size.Width() += nAdd; }
     168           0 : void SwRect::AddHeight( const long nAdd ) { m_Size.Height() += nAdd; }
     169       82571 : void SwRect::SubLeft( const long nSub ){ m_Size.Width() += nSub; m_Point.setX(m_Point.getX() - nSub); }
     170      142839 : void SwRect::AddRight( const long nAdd ){ m_Size.Width() += nAdd; }
     171       73622 : void SwRect::SubTop( const long nSub ){ m_Size.Height() += nSub; m_Point.setY(m_Point.getY() - nSub); }
     172      137358 : void SwRect::AddBottom( const long nAdd ){ m_Size.Height() += nAdd; }
     173       57565 : void SwRect::SetPosX( const long nNew ){ m_Point.setX(nNew); }
     174       82199 : 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      456121 : const Point SwRect::TopLeft() const { return Pos(); }
     180        8967 : const Point SwRect::TopRight() const { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() ); }
     181        8923 : const Point SwRect::BottomLeft() const { return Point( m_Point.getX(), m_Point.getY() + m_Size.getHeight() ); }
     182        8923 : const Point SwRect::BottomRight() const
     183        8923 :     { return Point( m_Point.getX() + m_Size.getWidth(), m_Point.getY() + m_Size.getHeight() ); }
     184             : 
     185       15754 : long SwRect::GetLeftDistance( long nLimit ) const { return m_Point.getX() - nLimit; }
     186      181415 : long SwRect::GetBottomDistance( long nLim ) const { return nLim - m_Point.getY() - m_Size.getHeight();}
     187      109813 : long SwRect::GetTopDistance( long nLimit ) const { return m_Point.getY() - nLimit; }
     188           4 : long SwRect::GetRightDistance( long nLim ) const { return nLim - m_Point.getX() - m_Size.getWidth(); }
     189             : 
     190       12806 : bool SwRect::OverStepLeft( long nLimit ) const
     191       12806 :     { return nLimit > m_Point.getX() && m_Point.getX() + m_Size.getWidth() > nLimit; }
     192       53720 : bool SwRect::OverStepBottom( long nLimit ) const
     193       53720 :     { return nLimit > m_Point.getY() && m_Point.getY() + m_Size.getHeight() > nLimit; }
     194           0 : bool SwRect::OverStepTop( long nLimit ) const
     195           0 :     { return nLimit > m_Point.getY() && m_Point.getY() + m_Size.getHeight() > nLimit; }
     196           0 : bool SwRect::OverStepRight( long nLimit ) const
     197           0 :     { return nLimit > m_Point.getX() && m_Point.getX() + m_Size.getWidth() > nLimit; }
     198             : 
     199         262 : void SwRect::SetLeftAndWidth( long nLeft, long nNew )
     200             : {
     201         262 :     m_Point.setX(nLeft);
     202         262 :     m_Size.setWidth(nNew);
     203         262 : }
     204       55020 : void SwRect::SetTopAndHeight( long nTop, long nNew )
     205             : {
     206       55020 :     m_Point.setY(nTop);
     207       55020 :     m_Size.setHeight(nNew);
     208       55020 : }
     209           3 : void SwRect::SetRightAndWidth( long nRight, long nNew )
     210             : {
     211           3 :     m_Point.setX(nRight - nNew);
     212           3 :     m_Size.setWidth(nNew);
     213           3 : }
     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       37720 : void SwRect::SetUpperLeftCorner(  const Point& rNew )
     220       37720 :     { m_Point = rNew; }
     221           5 : void SwRect::SetUpperRightCorner(  const Point& rNew )
     222           5 :     { 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             : #ifdef DBG_UTIL
     227             : SvStream& WriteSwRect(SvStream &rStream, const SwRect &rRect)
     228             : {
     229             :     rStream.WriteChar('[').WriteInt32(rRect.Top()).
     230             :             WriteChar('/').WriteInt32(rRect.Left()).
     231             :             WriteChar(',').WriteInt32(rRect.Width()).
     232             :             WriteChar('x').WriteInt32(rRect.Height()).
     233             :             WriteCharPtr("] ");
     234             :     return rStream;
     235             : }
     236             : #endif
     237             : 
     238             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11