LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basegfx/range - b2drange.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 69 82 84.1 %
Date: 2012-08-25 Functions: 23 28 82.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 28 75.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef _BGFX_RANGE_B2DRANGE_HXX
      30                 :            : #define _BGFX_RANGE_B2DRANGE_HXX
      31                 :            : 
      32                 :            : #include <basegfx/vector/b2dvector.hxx>
      33                 :            : #include <basegfx/point/b2dpoint.hxx>
      34                 :            : #include <basegfx/tuple/b2dtuple.hxx>
      35                 :            : #include <basegfx/range/basicrange.hxx>
      36                 :            : #include <vector>
      37                 :            : #include <basegfx/basegfxdllapi.h>
      38                 :            : 
      39                 :            : 
      40                 :            : namespace basegfx
      41                 :            : {
      42                 :            :     // predeclarations
      43                 :            :     class B2IRange;
      44                 :            :     class B2DHomMatrix;
      45                 :            : 
      46                 :            :     /** A two-dimensional interval over doubles
      47                 :            : 
      48                 :            :         This is a set of real numbers, bounded by a lower and an upper
      49                 :            :         pair. All inbetween values are included in the set (see also
      50                 :            :         http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
      51                 :            : 
      52                 :            :         The set is closed, i.e. the upper and the lower bound are
      53                 :            :         included (if you're used to the notation - we're talking about
      54                 :            :         [a,b] here, compared to half-open [a,b) or open intervals
      55                 :            :         (a,b)).
      56                 :            : 
      57                 :            :         That means, isInside(val) will return true also for values of
      58                 :            :         val=a or val=b.
      59                 :            : 
      60                 :            :         @see B1DRange
      61                 :            :      */
      62                 :            :     class B2DRange
      63                 :            :     {
      64                 :            :     public:
      65                 :            :         typedef double          ValueType;
      66                 :            :         typedef DoubleTraits    TraitsType;
      67                 :            : 
      68                 :    4492947 :         B2DRange() {}
      69                 :            : 
      70                 :            :         /// Create degenerate interval consisting of a single point
      71                 :      13786 :         explicit B2DRange(const B2DTuple& rTuple)
      72                 :            :         :   maRangeX(rTuple.getX()),
      73                 :      13786 :             maRangeY(rTuple.getY())
      74                 :            :         {
      75                 :      13786 :         }
      76                 :            : 
      77                 :            :         /// Create proper interval between the two given double pairs
      78                 :    1421240 :         B2DRange(double x1,
      79                 :            :                  double y1,
      80                 :            :                  double x2,
      81                 :            :                  double y2)
      82                 :            :         :   maRangeX(x1),
      83                 :    1421240 :             maRangeY(y1)
      84                 :            :         {
      85                 :    1421240 :             maRangeX.expand(x2);
      86                 :    1421240 :             maRangeY.expand(y2);
      87                 :    1421240 :         }
      88                 :            : 
      89                 :            :         /// Create proper interval between the two given points
      90                 :          0 :         B2DRange(const B2DTuple& rTuple1,
      91                 :            :                  const B2DTuple& rTuple2)
      92                 :            :         :   maRangeX(rTuple1.getX()),
      93                 :          0 :             maRangeY(rTuple1.getY())
      94                 :            :         {
      95                 :          0 :             expand( rTuple2 );
      96                 :          0 :         }
      97                 :            : 
      98                 :            :         BASEGFX_DLLPUBLIC explicit B2DRange(const B2IRange& rRange);
      99                 :            : 
     100                 :            :         /** Check if the interval set is empty
     101                 :            : 
     102                 :            :             @return false, if no value is in this set - having a
     103                 :            :             single point included will already return true.
     104                 :            :          */
     105                 :     818032 :         bool isEmpty() const
     106                 :            :         {
     107                 :            :             return (
     108                 :     818032 :                 maRangeX.isEmpty()
     109                 :     686351 :                 || maRangeY.isEmpty()
     110   [ +  +  +  + ]:    1504383 :                 );
     111                 :            :         }
     112                 :            : 
     113                 :            :         /// reset the object to empty state again, clearing all values
     114                 :      13445 :         void reset()
     115                 :            :         {
     116                 :      13445 :             maRangeX.reset();
     117                 :      13445 :             maRangeY.reset();
     118                 :      13445 :         }
     119                 :            : 
     120                 :       1958 :         bool operator==( const B2DRange& rRange ) const
     121                 :            :         {
     122                 :       1958 :             return (maRangeX == rRange.maRangeX
     123 [ +  + ][ +  + ]:       1958 :                 && maRangeY == rRange.maRangeY);
     124                 :            :         }
     125                 :            : 
     126                 :        150 :         bool operator!=( const B2DRange& rRange ) const
     127                 :            :         {
     128                 :        150 :             return (maRangeX != rRange.maRangeX
     129 [ -  + ][ +  + ]:        150 :                 || maRangeY != rRange.maRangeY);
     130                 :            :         }
     131                 :            : 
     132                 :          0 :         bool equal(const B2DRange& rRange) const
     133                 :            :         {
     134                 :          0 :             return (maRangeX.equal(rRange.maRangeX)
     135 [ #  # ][ #  # ]:          0 :                     && maRangeY.equal(rRange.maRangeY));
     136                 :            :         }
     137                 :            : 
     138                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     139                 :     489241 :         double getMinX() const
     140                 :            :         {
     141                 :     489241 :             return maRangeX.getMinimum();
     142                 :            :         }
     143                 :            : 
     144                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     145                 :    4195432 :         double getMinY() const
     146                 :            :         {
     147                 :    4195432 :             return maRangeY.getMinimum();
     148                 :            :         }
     149                 :            : 
     150                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     151                 :     179318 :         double getMaxX() const
     152                 :            :         {
     153                 :     179318 :             return maRangeX.getMaximum();
     154                 :            :         }
     155                 :            : 
     156                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     157                 :    3885503 :         double getMaxY() const
     158                 :            :         {
     159                 :    3885503 :             return maRangeY.getMaximum();
     160                 :            :         }
     161                 :            : 
     162                 :            :         /// return difference between upper and lower X value. returns 0 for empty sets.
     163                 :     339566 :         double getWidth() const
     164                 :            :         {
     165                 :     339566 :             return maRangeX.getRange();
     166                 :            :         }
     167                 :            : 
     168                 :            :         /// return difference between upper and lower Y value. returns 0 for empty sets.
     169                 :     337179 :         double getHeight() const
     170                 :            :         {
     171                 :     337179 :             return maRangeY.getRange();
     172                 :            :         }
     173                 :            : 
     174                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     175                 :        104 :         B2DPoint getMinimum() const
     176                 :            :         {
     177                 :            :             return B2DPoint(
     178                 :            :                 maRangeX.getMinimum(),
     179                 :            :                 maRangeY.getMinimum()
     180                 :        104 :                 );
     181                 :            :         }
     182                 :            : 
     183                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     184                 :          0 :         B2DPoint getMaximum() const
     185                 :            :         {
     186                 :            :             return B2DPoint(
     187                 :            :                 maRangeX.getMaximum(),
     188                 :            :                 maRangeY.getMaximum()
     189                 :          0 :                 );
     190                 :            :         }
     191                 :            : 
     192                 :            :         /// return difference between upper and lower point. returns (0,0) for empty sets.
     193                 :        104 :         B2DVector getRange() const
     194                 :            :         {
     195                 :            :             return B2DVector(
     196                 :            :                 maRangeX.getRange(),
     197                 :            :                 maRangeY.getRange()
     198                 :        104 :                 );
     199                 :            :         }
     200                 :            : 
     201                 :            :         /// return center point of set. returns (0,0) for empty sets.
     202                 :          6 :         B2DPoint getCenter() const
     203                 :            :         {
     204                 :            :             return B2DPoint(
     205                 :            :                 maRangeX.getCenter(),
     206                 :            :                 maRangeY.getCenter()
     207                 :          6 :                 );
     208                 :            :         }
     209                 :            : 
     210                 :            :         /// return center X value of set. returns 0 for empty sets.
     211                 :          0 :         double getCenterX() const
     212                 :            :         {
     213                 :          0 :             return maRangeX.getCenter();
     214                 :            :         }
     215                 :            : 
     216                 :            :         /// return center Y value of set. returns 0 for empty sets.
     217                 :          0 :         double getCenterY() const
     218                 :            :         {
     219                 :          0 :             return maRangeY.getCenter();
     220                 :            :         }
     221                 :            : 
     222                 :            :         /// yields true if given point is contained in set
     223                 :          4 :         bool isInside(const B2DTuple& rTuple) const
     224                 :            :         {
     225                 :            :             return (
     226                 :          4 :                 maRangeX.isInside(rTuple.getX())
     227                 :          4 :                 && maRangeY.isInside(rTuple.getY())
     228   [ +  -  +  - ]:          8 :                 );
     229                 :            :         }
     230                 :            : 
     231                 :            :         /// yields true if rRange is inside, or equal to set
     232                 :        558 :         bool isInside(const B2DRange& rRange) const
     233                 :            :         {
     234                 :            :             return (
     235                 :        558 :                 maRangeX.isInside(rRange.maRangeX)
     236                 :        529 :                 && maRangeY.isInside(rRange.maRangeY)
     237   [ +  +  +  + ]:       1087 :                 );
     238                 :            :         }
     239                 :            : 
     240                 :            :         /// yields true if rRange at least partly inside set
     241                 :      96781 :         bool overlaps(const B2DRange& rRange) const
     242                 :            :         {
     243                 :            :             return (
     244                 :      96781 :                 maRangeX.overlaps(rRange.maRangeX)
     245                 :      92130 :                 && maRangeY.overlaps(rRange.maRangeY)
     246   [ +  +  +  + ]:     188911 :                 );
     247                 :            :         }
     248                 :            : 
     249                 :            :         /// yields true if overlaps(rRange) does, and the overlap is larger than infinitesimal
     250                 :            :         bool overlapsMore(const B2DRange& rRange) const
     251                 :            :         {
     252                 :            :             return (
     253                 :            :                 maRangeX.overlapsMore(rRange.maRangeX)
     254                 :            :                 && maRangeY.overlapsMore(rRange.maRangeY)
     255                 :            :                 );
     256                 :            :         }
     257                 :            : 
     258                 :            :         /// add point to the set, expanding as necessary
     259                 :     133808 :         void expand(const B2DTuple& rTuple)
     260                 :            :         {
     261                 :     133808 :             maRangeX.expand(rTuple.getX());
     262                 :     133808 :             maRangeY.expand(rTuple.getY());
     263                 :     133808 :         }
     264                 :            : 
     265                 :            :         /// add rRange to the set, expanding as necessary
     266                 :    4580700 :         void expand(const B2DRange& rRange)
     267                 :            :         {
     268                 :    4580700 :             maRangeX.expand(rRange.maRangeX);
     269                 :    4580700 :             maRangeY.expand(rRange.maRangeY);
     270                 :    4580700 :         }
     271                 :            : 
     272                 :            :         /// calc set intersection
     273                 :      47584 :         void intersect(const B2DRange& rRange)
     274                 :            :         {
     275                 :      47584 :             maRangeX.intersect(rRange.maRangeX);
     276                 :      47584 :             maRangeY.intersect(rRange.maRangeY);
     277                 :      47584 :         }
     278                 :            : 
     279                 :            :         /// grow set by fValue on all sides
     280                 :     373088 :         void grow(double fValue)
     281                 :            :         {
     282                 :     373088 :             maRangeX.grow(fValue);
     283                 :     373088 :             maRangeY.grow(fValue);
     284                 :     373088 :         }
     285                 :            : 
     286                 :            :         BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix& rMatrix);
     287                 :            : 
     288                 :            :     private:
     289                 :            :         typedef ::basegfx::BasicRange< ValueType, TraitsType >  MyBasicRange;
     290                 :            : 
     291                 :            :         MyBasicRange        maRangeX;
     292                 :            :         MyBasicRange        maRangeY;
     293                 :            :     };
     294                 :            : 
     295                 :            :     /** Round double to nearest integer for 2D range
     296                 :            : 
     297                 :            :         @return the nearest integer for this range
     298                 :            :     */
     299                 :            :     BASEGFX_DLLPUBLIC B2IRange fround(const B2DRange& rRange);
     300                 :            : 
     301                 :            :     /** Compute the set difference of the two given ranges
     302                 :            : 
     303                 :            :         This method calculates the symmetric difference (aka XOR)
     304                 :            :         between the two given ranges, and returning the resulting
     305                 :            :         ranges. Thus, the result will contain all areas where one, but
     306                 :            :         not both ranges lie.
     307                 :            : 
     308                 :            :         @param o_rResult
     309                 :            :         Result vector. The up to four difference ranges are returned
     310                 :            :         within this vector
     311                 :            : 
     312                 :            :         @param rFirst
     313                 :            :         The first range
     314                 :            : 
     315                 :            :         @param rSecond
     316                 :            :         The second range
     317                 :            : 
     318                 :            :         @return the input vector
     319                 :            :      */
     320                 :            :     BASEGFX_DLLPUBLIC ::std::vector< B2DRange >& computeSetDifference( ::std::vector< B2DRange >&   o_rResult,
     321                 :            :                                                      const B2DRange&            rFirst,
     322                 :            :                                                      const B2DRange&            rSecond );
     323                 :            : 
     324                 :            : } // end of namespace basegfx
     325                 :            : 
     326                 :            : 
     327                 :            : #endif /* _BGFX_RANGE_B2DRANGE_HXX */
     328                 :            : 
     329                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10