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

Generated by: LCOV version 1.10