LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/basegfx/range - b2drange.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 59 82 72.0 %
Date: 2012-12-27 Functions: 20 28 71.4 %
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 _BGFX_RANGE_B2DRANGE_HXX
      21             : #define _BGFX_RANGE_B2DRANGE_HXX
      22             : 
      23             : #include <basegfx/vector/b2dvector.hxx>
      24             : #include <basegfx/point/b2dpoint.hxx>
      25             : #include <basegfx/tuple/b2dtuple.hxx>
      26             : #include <basegfx/range/basicrange.hxx>
      27             : #include <vector>
      28             : #include <basegfx/basegfxdllapi.h>
      29             : 
      30             : 
      31             : namespace basegfx
      32             : {
      33             :     // predeclarations
      34             :     class B2IRange;
      35             :     class B2DHomMatrix;
      36             : 
      37             :     /** A two-dimensional interval over doubles
      38             : 
      39             :         This is a set of real numbers, bounded by a lower and an upper
      40             :         pair. All inbetween values are included in the set (see also
      41             :         http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
      42             : 
      43             :         The set is closed, i.e. the upper and the lower bound are
      44             :         included (if you're used to the notation - we're talking about
      45             :         [a,b] here, compared to half-open [a,b) or open intervals
      46             :         (a,b)).
      47             : 
      48             :         That means, isInside(val) will return true also for values of
      49             :         val=a or val=b.
      50             : 
      51             :         @see B1DRange
      52             :      */
      53             :     class B2DRange
      54             :     {
      55             :     public:
      56             :         typedef double          ValueType;
      57             :         typedef DoubleTraits    TraitsType;
      58             : 
      59       13154 :         B2DRange() {}
      60             : 
      61             :         /// Create degenerate interval consisting of a single point
      62         139 :         explicit B2DRange(const B2DTuple& rTuple)
      63             :         :   maRangeX(rTuple.getX()),
      64         139 :             maRangeY(rTuple.getY())
      65             :         {
      66         139 :         }
      67             : 
      68             :         /// Create proper interval between the two given double pairs
      69       34136 :         B2DRange(double x1,
      70             :                  double y1,
      71             :                  double x2,
      72             :                  double y2)
      73             :         :   maRangeX(x1),
      74       34136 :             maRangeY(y1)
      75             :         {
      76       34136 :             maRangeX.expand(x2);
      77       34136 :             maRangeY.expand(y2);
      78       34136 :         }
      79             : 
      80             :         /// Create proper interval between the two given points
      81           0 :         B2DRange(const B2DTuple& rTuple1,
      82             :                  const B2DTuple& rTuple2)
      83             :         :   maRangeX(rTuple1.getX()),
      84           0 :             maRangeY(rTuple1.getY())
      85             :         {
      86           0 :             expand( rTuple2 );
      87           0 :         }
      88             : 
      89             :         BASEGFX_DLLPUBLIC explicit B2DRange(const B2IRange& rRange);
      90             : 
      91             :         /** Check if the interval set is empty
      92             : 
      93             :             @return false, if no value is in this set - having a
      94             :             single point included will already return true.
      95             :          */
      96        2392 :         bool isEmpty() const
      97             :         {
      98             :             return (
      99        2392 :                 maRangeX.isEmpty()
     100        1542 :                 || maRangeY.isEmpty()
     101        3934 :                 );
     102             :         }
     103             : 
     104             :         /// reset the object to empty state again, clearing all values
     105          45 :         void reset()
     106             :         {
     107          45 :             maRangeX.reset();
     108          45 :             maRangeY.reset();
     109          45 :         }
     110             : 
     111         194 :         bool operator==( const B2DRange& rRange ) const
     112             :         {
     113         194 :             return (maRangeX == rRange.maRangeX
     114         194 :                 && maRangeY == rRange.maRangeY);
     115             :         }
     116             : 
     117          46 :         bool operator!=( const B2DRange& rRange ) const
     118             :         {
     119          46 :             return (maRangeX != rRange.maRangeX
     120          46 :                 || maRangeY != rRange.maRangeY);
     121             :         }
     122             : 
     123           0 :         bool equal(const B2DRange& rRange) const
     124             :         {
     125           0 :             return (maRangeX.equal(rRange.maRangeX)
     126           0 :                     && maRangeY.equal(rRange.maRangeY));
     127             :         }
     128             : 
     129             :         /// get lower bound of the set. returns arbitrary values for empty sets.
     130        3004 :         double getMinX() const
     131             :         {
     132        3004 :             return maRangeX.getMinimum();
     133             :         }
     134             : 
     135             :         /// get lower bound of the set. returns arbitrary values for empty sets.
     136       81989 :         double getMinY() const
     137             :         {
     138       81989 :             return maRangeY.getMinimum();
     139             :         }
     140             : 
     141             :         /// get upper bound of the set. returns arbitrary values for empty sets.
     142        2628 :         double getMaxX() const
     143             :         {
     144        2628 :             return maRangeX.getMaximum();
     145             :         }
     146             : 
     147             :         /// get upper bound of the set. returns arbitrary values for empty sets.
     148       81613 :         double getMaxY() const
     149             :         {
     150       81613 :             return maRangeY.getMaximum();
     151             :         }
     152             : 
     153             :         /// return difference between upper and lower X value. returns 0 for empty sets.
     154         528 :         double getWidth() const
     155             :         {
     156         528 :             return maRangeX.getRange();
     157             :         }
     158             : 
     159             :         /// return difference between upper and lower Y value. returns 0 for empty sets.
     160         552 :         double getHeight() const
     161             :         {
     162         552 :             return maRangeY.getRange();
     163             :         }
     164             : 
     165             :         /// get lower bound of the set. returns arbitrary values for empty sets.
     166          34 :         B2DPoint getMinimum() const
     167             :         {
     168             :             return B2DPoint(
     169             :                 maRangeX.getMinimum(),
     170             :                 maRangeY.getMinimum()
     171          34 :                 );
     172             :         }
     173             : 
     174             :         /// get upper bound of the set. returns arbitrary values for empty sets.
     175           0 :         B2DPoint getMaximum() const
     176             :         {
     177             :             return B2DPoint(
     178             :                 maRangeX.getMaximum(),
     179             :                 maRangeY.getMaximum()
     180           0 :                 );
     181             :         }
     182             : 
     183             :         /// return difference between upper and lower point. returns (0,0) for empty sets.
     184          34 :         B2DVector getRange() const
     185             :         {
     186             :             return B2DVector(
     187             :                 maRangeX.getRange(),
     188             :                 maRangeY.getRange()
     189          34 :                 );
     190             :         }
     191             : 
     192             :         /// return center point of set. returns (0,0) for empty sets.
     193           0 :         B2DPoint getCenter() const
     194             :         {
     195             :             return B2DPoint(
     196             :                 maRangeX.getCenter(),
     197             :                 maRangeY.getCenter()
     198           0 :                 );
     199             :         }
     200             : 
     201             :         /// return center X value of set. returns 0 for empty sets.
     202           0 :         double getCenterX() const
     203             :         {
     204           0 :             return maRangeX.getCenter();
     205             :         }
     206             : 
     207             :         /// return center Y value of set. returns 0 for empty sets.
     208           0 :         double getCenterY() const
     209             :         {
     210           0 :             return maRangeY.getCenter();
     211             :         }
     212             : 
     213             :         /// yields true if given point is contained in set
     214           0 :         bool isInside(const B2DTuple& rTuple) const
     215             :         {
     216             :             return (
     217           0 :                 maRangeX.isInside(rTuple.getX())
     218           0 :                 && maRangeY.isInside(rTuple.getY())
     219           0 :                 );
     220             :         }
     221             : 
     222             :         /// yields true if rRange is inside, or equal to set
     223           0 :         bool isInside(const B2DRange& rRange) const
     224             :         {
     225             :             return (
     226           0 :                 maRangeX.isInside(rRange.maRangeX)
     227           0 :                 && maRangeY.isInside(rRange.maRangeY)
     228           0 :                 );
     229             :         }
     230             : 
     231             :         /// yields true if rRange at least partly inside set
     232         428 :         bool overlaps(const B2DRange& rRange) const
     233             :         {
     234             :             return (
     235         428 :                 maRangeX.overlaps(rRange.maRangeX)
     236         419 :                 && maRangeY.overlaps(rRange.maRangeY)
     237         847 :                 );
     238             :         }
     239             : 
     240             :         /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
     241             :         bool overlapsMore(const B2DRange& rRange) const
     242             :         {
     243             :             return (
     244             :                 maRangeX.overlapsMore(rRange.maRangeX)
     245             :                 && maRangeY.overlapsMore(rRange.maRangeY)
     246             :                 );
     247             :         }
     248             : 
     249             :         /// add point to the set, expanding as necessary
     250        2303 :         void expand(const B2DTuple& rTuple)
     251             :         {
     252        2303 :             maRangeX.expand(rTuple.getX());
     253        2303 :             maRangeY.expand(rTuple.getY());
     254        2303 :         }
     255             : 
     256             :         /// add rRange to the set, expanding as necessary
     257        6222 :         void expand(const B2DRange& rRange)
     258             :         {
     259        6222 :             maRangeX.expand(rRange.maRangeX);
     260        6222 :             maRangeY.expand(rRange.maRangeY);
     261        6222 :         }
     262             : 
     263             :         /// calc set intersection
     264         812 :         void intersect(const B2DRange& rRange)
     265             :         {
     266         812 :             maRangeX.intersect(rRange.maRangeX);
     267         812 :             maRangeY.intersect(rRange.maRangeY);
     268         812 :         }
     269             : 
     270             :         /// grow set by fValue on all sides
     271         164 :         void grow(double fValue)
     272             :         {
     273         164 :             maRangeX.grow(fValue);
     274         164 :             maRangeY.grow(fValue);
     275         164 :         }
     276             : 
     277             :         BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix& rMatrix);
     278             : 
     279             :     private:
     280             :         typedef ::basegfx::BasicRange< ValueType, TraitsType >  MyBasicRange;
     281             : 
     282             :         MyBasicRange        maRangeX;
     283             :         MyBasicRange        maRangeY;
     284             :     };
     285             : 
     286             :     /** Round double to nearest integer for 2D range
     287             : 
     288             :         @return the nearest integer for this range
     289             :     */
     290             :     BASEGFX_DLLPUBLIC B2IRange fround(const B2DRange& rRange);
     291             : 
     292             :     /** Compute the set difference of the two given ranges
     293             : 
     294             :         This method calculates the symmetric difference (aka XOR)
     295             :         between the two given ranges, and returning the resulting
     296             :         ranges. Thus, the result will contain all areas where one, but
     297             :         not both ranges lie.
     298             : 
     299             :         @param o_rResult
     300             :         Result vector. The up to four difference ranges are returned
     301             :         within this vector
     302             : 
     303             :         @param rFirst
     304             :         The first range
     305             : 
     306             :         @param rSecond
     307             :         The second range
     308             : 
     309             :         @return the input vector
     310             :      */
     311             :     BASEGFX_DLLPUBLIC ::std::vector< B2DRange >& computeSetDifference( ::std::vector< B2DRange >&   o_rResult,
     312             :                                                      const B2DRange&            rFirst,
     313             :                                                      const B2DRange&            rSecond );
     314             : 
     315             : } // end of namespace basegfx
     316             : 
     317             : 
     318             : #endif /* _BGFX_RANGE_B2DRANGE_HXX */
     319             : 
     320             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10