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