LCOV - code coverage report
Current view: top level - include/basegfx/range - b1ibox.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 21 21 100.0 %
Date: 2014-11-03 Functions: 9 9 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_B1IBOX_HXX
      21             : #define INCLUDED_BASEGFX_RANGE_B1IBOX_HXX
      22             : 
      23             : #include <basegfx/range/basicbox.hxx>
      24             : #include <basegfx/basegfxdllapi.h>
      25             : 
      26             : 
      27             : namespace basegfx
      28             : {
      29             :     /** A one-dimensional interval over integers
      30             : 
      31             :         This is most easily depicted as a set of integers, bounded by
      32             :         a lower and an upper value - but excluding the upper
      33             :         value. All inbetween values are included in the set (see also
      34             :         http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
      35             : 
      36             :         The set is half-open, i.e. the lower bound is included, the
      37             :         upper bound not (if you're used to the notation - we're
      38             :         talking about [a,b) here, compared to closed [a,b] or fully
      39             :         open intervals (a,b)).
      40             : 
      41             :         If you don't need a half-open interval, check B1IRange.
      42             : 
      43             :         That means, isInside(val) will return true also for values of
      44             :         val=a, but not for val=b.
      45             : 
      46             :         @see B1IRange
      47             :      */
      48             :     class B1IBox
      49             :     {
      50             :         ::basegfx::BasicBox maRange;
      51             : 
      52             :     public:
      53           2 :         B1IBox() {}
      54             : 
      55             :         /// Create degenerate interval that's still empty
      56             :         explicit B1IBox(sal_Int32 nStartValue)
      57             :         :   maRange(nStartValue)
      58             :         {
      59             :         }
      60             : 
      61             :         /// Create proper interval between the two given values
      62           8 :         B1IBox(sal_Int32 nStartValue1, sal_Int32 nStartValue2)
      63           8 :         :   maRange(nStartValue1)
      64             :         {
      65           8 :             expand(nStartValue2);
      66           8 :         }
      67             : 
      68             :         /** Check if the interval set is empty
      69             : 
      70             :             @return false, if no value is in this set - having a
      71             :             single value included will still return false.
      72             :          */
      73           8 :         bool isEmpty() const
      74             :         {
      75           8 :             return maRange.isEmpty();
      76             :         }
      77             : 
      78             :         /// reset the object to empty state again, clearing all values
      79             :         void reset()
      80             :         {
      81             :             maRange.reset();
      82             :         }
      83             : 
      84             :         bool operator==( const B1IBox& rBox ) const
      85             :         {
      86             :             return (maRange == rBox.maRange);
      87             :         }
      88             : 
      89             :         bool operator!=( const B1IBox& rBox ) const
      90             :         {
      91             :             return (maRange != rBox.maRange);
      92             :         }
      93             : 
      94             :         /// get lower bound of the set. returns arbitrary values for empty sets.
      95             :         sal_Int32 getMinimum() const
      96             :         {
      97             :             return maRange.getMinimum();
      98             :         }
      99             : 
     100             :         /// get upper bound of the set. returns arbitrary values for empty sets.
     101             :         sal_Int32 getMaximum() const
     102             :         {
     103             :             return maRange.getMaximum();
     104             :         }
     105             : 
     106             :         /// return difference between upper and lower value. returns 0 for empty sets.
     107           4 :         Int32Traits::DifferenceType getRange() const
     108             :         {
     109           4 :             return maRange.getRange();
     110             :         }
     111             : 
     112             :         /// return middle of upper and lower value. returns 0 for empty sets.
     113           4 :         double getCenter() const
     114             :         {
     115           4 :             return maRange.getCenter();
     116             :         }
     117             : 
     118             :         /// yields true if value is contained in set
     119           6 :         bool isInside(sal_Int32 nValue) const
     120             :         {
     121           6 :             return maRange.isInside(nValue);
     122             :         }
     123             : 
     124             :         /// yields true if rRange is inside, or equal to set
     125             :         bool isInside(const B1IBox& rBox) const
     126             :         {
     127             :             return maRange.isInside(rBox.maRange);
     128             :         }
     129             : 
     130             :         /// yields true if rRange at least partly inside set
     131           4 :         bool overlaps(const B1IBox& rBox) const
     132             :         {
     133           4 :             return maRange.overlaps(rBox.maRange);
     134             :         }
     135             : 
     136             :         /// add nValue to the set, expanding as necessary
     137          14 :         void expand(sal_Int32 nValue)
     138             :         {
     139          14 :             maRange.expand(nValue);
     140          14 :         }
     141             : 
     142             :         /// add rBox to the set, expanding as necessary
     143             :         void expand(const B1IBox& rBox)
     144             :         {
     145             :             maRange.expand(rBox.maRange);
     146             :         }
     147             : 
     148             :         /// calc set intersection
     149           4 :         void intersect(const B1IBox& rBox)
     150             :         {
     151           4 :             maRange.intersect(rBox.maRange);
     152           4 :         }
     153             : 
     154             :         /// grow set by nValue on both sides
     155             :         void grow(sal_Int32 nValue)
     156             :         {
     157             :             maRange.grow(nValue);
     158             :         }
     159             :     };
     160             : } // end of namespace basegfx
     161             : 
     162             : #endif // INCLUDED_BASEGFX_RANGE_B1IBOX_HXX
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10