LCOV - code coverage report
Current view: top level - include/basegfx/range - basicbox.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 18 20 90.0 %
Date: 2014-11-03 Functions: 6 6 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             : #ifndef INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
      21             : #define INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
      22             : 
      23             : #include <basegfx/range/basicrange.hxx>
      24             : #include <basegfx/basegfxdllapi.h>
      25             : 
      26             : 
      27             : namespace basegfx
      28             : {
      29             :     /** Explicitely different from BasicRange, handling the inside predicates
      30             :         differently.
      31             : 
      32             :         This is modelled after how polygon fill algorithms set pixel -
      33             :         typically excluding rightmost and bottommost ones.
      34             :      */
      35             :     class BasicBox : public BasicRange< sal_Int32, Int32Traits >
      36             :     {
      37             :         typedef BasicRange< sal_Int32, Int32Traits > Base;
      38             :     public:
      39     3660946 :         BasicBox() {}
      40             : 
      41    51802280 :         explicit BasicBox( sal_Int32 nValue ) :
      42    51802280 :             Base( nValue )
      43             :         {
      44    51802280 :         }
      45             : 
      46   265605063 :         bool isEmpty() const
      47             :         {
      48   265605063 :             return mnMinimum >= mnMaximum;
      49             :         }
      50             : 
      51           4 :         double getCenter() const
      52             :         {
      53           4 :             if(isEmpty())
      54             :             {
      55           2 :                 return 0.0;
      56             :             }
      57             :             else
      58             :             {
      59           2 :                 return ((mnMaximum + mnMinimum - 1.0) / 2.0);
      60             :             }
      61             :         }
      62             : 
      63             :         using Base::isInside;
      64             : 
      65   249752373 :         bool isInside(sal_Int32 nValue) const
      66             :         {
      67   249752373 :             if(isEmpty())
      68             :             {
      69           6 :                 return false;
      70             :             }
      71             :             else
      72             :             {
      73   249752367 :                 return (nValue >= mnMinimum) && (nValue < mnMaximum);
      74             :             }
      75             :         }
      76             : 
      77             :         using Base::overlaps;
      78             : 
      79           4 :         bool overlaps(const BasicBox& rBox) const
      80             :         {
      81           4 :             if(isEmpty())
      82             :             {
      83           0 :                 return false;
      84             :             }
      85             :             else
      86             :             {
      87           4 :                 if(rBox.isEmpty())
      88             :                 {
      89           0 :                     return false;
      90             :                 }
      91             :                 else
      92             :                 {
      93           4 :                     return !((rBox.mnMaximum <= mnMinimum) || (rBox.mnMinimum >= mnMaximum));
      94             :                 }
      95             :             }
      96             :         }
      97             : 
      98             :         void grow(sal_Int32 nValue)
      99             :         {
     100             :             if(!isEmpty())
     101             :             {
     102             :                 bool bLessThanZero(nValue < 0);
     103             : 
     104             :                 if(nValue > 0 || bLessThanZero)
     105             :                 {
     106             :                     mnMinimum -= nValue;
     107             :                     mnMaximum += nValue;
     108             : 
     109             :                     if(bLessThanZero)
     110             :                     {
     111             :                         // test if range did collapse
     112             :                         if(mnMinimum > mnMaximum)
     113             :                         {
     114             :                             // if yes, collapse to center
     115             :                             mnMinimum = mnMaximum = ((mnMaximum + mnMinimum - 1) / 2);
     116             :                         }
     117             :                     }
     118             :                 }
     119             :             }
     120             :         }
     121             :     };
     122             : 
     123             : } // end of namespace basegfx
     124             : 
     125             : #endif // INCLUDED_BASEGFX_RANGE_BASICBOX_HXX
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10