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

Generated by: LCOV version 1.11