LCOV - code coverage report
Current view: top level - include/basegfx/range - basicbox.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 18 20 90.0 %
Date: 2014-04-11 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     1860875 :         BasicBox() {}
      40             : 
      41    20274632 :         explicit BasicBox( sal_Int32 nValue ) :
      42    20274632 :             Base( nValue )
      43             :         {
      44    20274632 :         }
      45             : 
      46   178708667 :         bool isEmpty() const
      47             :         {
      48   178708667 :             return mnMinimum >= mnMaximum;
      49             :         }
      50             : 
      51           2 :         double getCenter() const
      52             :         {
      53           2 :             if(isEmpty())
      54             :             {
      55           1 :                 return 0.0;
      56             :             }
      57             :             else
      58             :             {
      59           1 :                 return ((mnMaximum + mnMinimum - 1.0) / 2.0);
      60             :             }
      61             :         }
      62             : 
      63             :         using Base::isInside;
      64             : 
      65   172499317 :         bool isInside(sal_Int32 nValue) const
      66             :         {
      67   172499317 :             if(isEmpty())
      68             :             {
      69         118 :                 return false;
      70             :             }
      71             :             else
      72             :             {
      73   172499199 :                 return (nValue >= mnMinimum) && (nValue < mnMaximum);
      74             :             }
      75             :         }
      76             : 
      77             :         using Base::overlaps;
      78             : 
      79           2 :         bool overlaps(const BasicBox& rBox) const
      80             :         {
      81           2 :             if(isEmpty())
      82             :             {
      83           0 :                 return false;
      84             :             }
      85             :             else
      86             :             {
      87           2 :                 if(rBox.isEmpty())
      88             :                 {
      89           0 :                     return false;
      90             :                 }
      91             :                 else
      92             :                 {
      93           2 :                     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