LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basegfx/range - b2ibox.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 40 40 100.0 %
Date: 2012-08-25 Functions: 15 15 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 8 100.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_B2IBOX_HXX
      30                 :            : #define _BGFX_RANGE_B2IBOX_HXX
      31                 :            : 
      32                 :            : #include <basegfx/point/b2ipoint.hxx>
      33                 :            : #include <basegfx/point/b2dpoint.hxx>
      34                 :            : #include <basegfx/tuple/b2ituple.hxx>
      35                 :            : #include <basegfx/tuple/b2i64tuple.hxx>
      36                 :            : #include <basegfx/range/basicbox.hxx>
      37                 :            : #include <vector>
      38                 :            : #include <basegfx/basegfxdllapi.h>
      39                 :            : 
      40                 :            : 
      41                 :            : namespace basegfx
      42                 :            : {
      43                 :            :     /** A two-dimensional interval over integers
      44                 :            : 
      45                 :            :         This is most easily depicted as a set of integers, bounded by
      46                 :            :         a lower and an upper value - but excluding the upper
      47                 :            :         value. All inbetween values are included in the set (see also
      48                 :            :         http://en.wikipedia.org/wiki/Interval_%28mathematics%29).
      49                 :            : 
      50                 :            :         The set is half-open, i.e. the lower bound is included, the
      51                 :            :         upper bound not (if you're used to the notation - we're
      52                 :            :         talking about [a,b) here, compared to closed [a,b] or fully
      53                 :            :         open intervals (a,b)).
      54                 :            : 
      55                 :            :         If you don't need a half-open interval, check B2IRange.
      56                 :            : 
      57                 :            :         That means, isInside(val) will return true also for values of
      58                 :            :         val=a, but not for val=b.
      59                 :            : 
      60                 :            :         Alternatively, consider this a rectangle, where the rightmost
      61                 :            :         pixel column and the bottommost pixel row are excluded - this
      62                 :            :         is much like polygon filling. As a result, filling a given
      63                 :            :         rectangle with basebmp::BitmapDevice::fillPolyPolygon(), will
      64                 :            :         affect exactly the same set of pixel as isInside() would
      65                 :            :         return true for.
      66                 :            : 
      67                 :            :         @see B2IRange
      68                 :            :      */
      69                 :            :     class B2IBox
      70                 :            :     {
      71                 :            :     public:
      72                 :            :         typedef sal_Int32       ValueType;
      73                 :            :         typedef Int32Traits     TraitsType;
      74                 :            : 
      75                 :    3162490 :         B2IBox() {}
      76                 :            : 
      77                 :            :         /// Create degenerate interval that's still empty
      78                 :            :         explicit B2IBox(const B2ITuple& rTuple)
      79                 :            :         :   maRangeX(rTuple.getX()),
      80                 :            :             maRangeY(rTuple.getY())
      81                 :            :         {
      82                 :            :         }
      83                 :            : 
      84                 :            :         /// Create proper interval between the two given points
      85                 :    8540937 :         B2IBox(sal_Int32 x1,
      86                 :            :                sal_Int32 y1,
      87                 :            :                sal_Int32 x2,
      88                 :            :                sal_Int32 y2) :
      89                 :            :             maRangeX(x1),
      90                 :    8540937 :             maRangeY(y1)
      91                 :            :         {
      92                 :    8540937 :             maRangeX.expand(x2);
      93                 :    8540937 :             maRangeY.expand(y2);
      94                 :    8540937 :         }
      95                 :            : 
      96                 :            :         /// Create proper interval between the two given points
      97                 :    9468696 :         B2IBox(const B2ITuple& rTuple1,
      98                 :            :                const B2ITuple& rTuple2) :
      99                 :            :             maRangeX(rTuple1.getX()),
     100                 :    9468696 :             maRangeY(rTuple1.getY())
     101                 :            :         {
     102                 :    9468696 :             expand( rTuple2 );
     103                 :    9468696 :         }
     104                 :            : 
     105                 :            :         /** Check if the interval set is empty
     106                 :            : 
     107                 :            :             @return false, if no value is in this set - having a
     108                 :            :             single value included will still return false.
     109                 :            :          */
     110                 :    5538788 :         bool isEmpty() const
     111                 :            :         {
     112 [ +  + ][ +  + ]:    5538788 :             return maRangeX.isEmpty() || maRangeY.isEmpty();
     113                 :            :         }
     114                 :            : 
     115                 :            :         /// reset the object to empty state again, clearing all values
     116                 :            :         void reset()
     117                 :            :         {
     118                 :            :             maRangeX.reset();
     119                 :            :             maRangeY.reset();
     120                 :            :         }
     121                 :            : 
     122                 :            :         bool operator==( const B2IBox& rBox ) const
     123                 :            :         {
     124                 :            :             return (maRangeX == rBox.maRangeX
     125                 :            :                 && maRangeY == rBox.maRangeY);
     126                 :            :         }
     127                 :            : 
     128                 :            :         bool operator!=( const B2IBox& rBox ) const
     129                 :            :         {
     130                 :            :             return (maRangeX != rBox.maRangeX
     131                 :            :                 || maRangeY != rBox.maRangeY);
     132                 :            :         }
     133                 :            : 
     134                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     135                 :   24106952 :         sal_Int32 getMinX() const
     136                 :            :         {
     137                 :   24106952 :             return maRangeX.getMinimum();
     138                 :            :         }
     139                 :            : 
     140                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     141                 :   24106952 :         sal_Int32 getMinY() const
     142                 :            :         {
     143                 :   24106952 :             return maRangeY.getMinimum();
     144                 :            :         }
     145                 :            : 
     146                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     147                 :   24043336 :         sal_Int32 getMaxX() const
     148                 :            :         {
     149                 :   24043336 :             return maRangeX.getMaximum();
     150                 :            :         }
     151                 :            : 
     152                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     153                 :   24043336 :         sal_Int32 getMaxY() const
     154                 :            :         {
     155                 :   24043336 :             return maRangeY.getMaximum();
     156                 :            :         }
     157                 :            : 
     158                 :            :         /// return difference between upper and lower X value. returns 0 for empty sets.
     159                 :    1373914 :         sal_Int64 getWidth() const
     160                 :            :         {
     161                 :    1373914 :             return maRangeX.getRange();
     162                 :            :         }
     163                 :            : 
     164                 :            :         /// return difference between upper and lower Y value. returns 0 for empty sets.
     165                 :    1373914 :         sal_Int64 getHeight() const
     166                 :            :         {
     167                 :    1373914 :             return maRangeY.getRange();
     168                 :            :         }
     169                 :            : 
     170                 :            :         /// get lower bound of the set. returns arbitrary values for empty sets.
     171                 :    9364125 :         B2IPoint getMinimum() const
     172                 :            :         {
     173                 :            :             return B2IPoint(
     174                 :            :                 maRangeX.getMinimum(),
     175                 :            :                 maRangeY.getMinimum()
     176                 :    9364125 :                 );
     177                 :            :         }
     178                 :            : 
     179                 :            :         /// get upper bound of the set. returns arbitrary values for empty sets.
     180                 :    4679503 :         B2IPoint getMaximum() const
     181                 :            :         {
     182                 :            :             return B2IPoint(
     183                 :            :                 maRangeX.getMaximum(),
     184                 :            :                 maRangeY.getMaximum()
     185                 :    4679503 :                 );
     186                 :            :         }
     187                 :            : 
     188                 :            :         /// return difference between upper and lower value. returns (0,0) for empty sets.
     189                 :            :         B2I64Tuple getRange() const
     190                 :            :         {
     191                 :            :             return B2I64Tuple(
     192                 :            :                 maRangeX.getRange(),
     193                 :            :                 maRangeY.getRange()
     194                 :            :                 );
     195                 :            :         }
     196                 :            : 
     197                 :            :         /// return center point of set. returns (0,0) for empty sets.
     198                 :            :         B2DPoint getCenter() const
     199                 :            :         {
     200                 :            :             return B2DPoint(
     201                 :            :                 maRangeX.getCenter(),
     202                 :            :                 maRangeY.getCenter()
     203                 :            :                 );
     204                 :            :         }
     205                 :            : 
     206                 :            :         /// yields true if point is contained in set
     207                 :   51666615 :         bool isInside(const B2ITuple& rTuple) const
     208                 :            :         {
     209                 :            :             return (
     210                 :   51666615 :                 maRangeX.isInside(rTuple.getX())
     211                 :   51613778 :                 && maRangeY.isInside(rTuple.getY())
     212   [ +  +  +  + ]:  103280393 :                 );
     213                 :            :         }
     214                 :            : 
     215                 :            :         /// yields true if rBox is inside, or equal to set
     216                 :            :         bool isInside(const B2IBox& rBox) const
     217                 :            :         {
     218                 :            :             return (
     219                 :            :                 maRangeX.isInside(rBox.maRangeX)
     220                 :            :                 && maRangeY.isInside(rBox.maRangeY)
     221                 :            :                 );
     222                 :            :         }
     223                 :            : 
     224                 :            :         /// yields true if rBox at least partly inside set
     225                 :            :         bool overlaps(const B2IBox& rBox) const
     226                 :            :         {
     227                 :            :             return (
     228                 :            :                 maRangeX.overlaps(rBox.maRangeX)
     229                 :            :                 && maRangeY.overlaps(rBox.maRangeY)
     230                 :            :                 );
     231                 :            :         }
     232                 :            : 
     233                 :            :         /// add point to the set, expanding as necessary
     234                 :    9468696 :         void expand(const B2ITuple& rTuple)
     235                 :            :         {
     236                 :    9468696 :             maRangeX.expand(rTuple.getX());
     237                 :    9468696 :             maRangeY.expand(rTuple.getY());
     238                 :    9468696 :         }
     239                 :            : 
     240                 :            :         /// add rBox to the set, expanding as necessary
     241                 :            :         void expand(const B2IBox& rBox)
     242                 :            :         {
     243                 :            :             maRangeX.expand(rBox.maRangeX);
     244                 :            :             maRangeY.expand(rBox.maRangeY);
     245                 :            :         }
     246                 :            : 
     247                 :            :         /// calc set intersection
     248                 :    5919513 :         void intersect(const B2IBox& rBox)
     249                 :            :         {
     250                 :    5919513 :             maRangeX.intersect(rBox.maRangeX);
     251                 :    5919513 :             maRangeY.intersect(rBox.maRangeY);
     252                 :    5919513 :         }
     253                 :            : 
     254                 :            :         /// grow set by nValue on all sides
     255                 :            :         void grow(sal_Int32 nValue)
     256                 :            :         {
     257                 :            :             maRangeX.grow(nValue);
     258                 :            :             maRangeY.grow(nValue);
     259                 :            :         }
     260                 :            : 
     261                 :            :     private:
     262                 :            :         BasicBox        maRangeX;
     263                 :            :         BasicBox        maRangeY;
     264                 :            :     };
     265                 :            : 
     266                 :            : } // end of namespace basegfx
     267                 :            : 
     268                 :            : #endif /* _BGFX_RANGE_B2IBOX_HXX */
     269                 :            : 
     270                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10