LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basegfx/tuple - b2i64tuple.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 9 0.0 %
Date: 2012-08-25 Functions: 0 4 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 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_TUPLE_B2I64TUPLE_HXX
      30                 :            : #define _BGFX_TUPLE_B2I64TUPLE_HXX
      31                 :            : 
      32                 :            : #include <sal/types.h>
      33                 :            : #include <basegfx/tuple/b2dtuple.hxx>
      34                 :            : #include <basegfx/basegfxdllapi.h>
      35                 :            : 
      36                 :            : 
      37                 :            : namespace basegfx
      38                 :            : {
      39                 :            :     /** Base class for all Points/Vectors with two sal_Int64 values
      40                 :            : 
      41                 :            :         This class provides all methods common to Point
      42                 :            :         avd Vector classes which are derived from here.
      43                 :            : 
      44                 :            :         @derive Use this class to implement Points or Vectors
      45                 :            :         which are based on two sal_Int64 values
      46                 :            :     */
      47                 :            :     class BASEGFX_DLLPUBLIC B2I64Tuple
      48                 :            :     {
      49                 :            :     protected:
      50                 :            :         sal_Int64                                       mnX;
      51                 :            :         sal_Int64                                       mnY;
      52                 :            : 
      53                 :            :     public:
      54                 :            :         /** Create a 2D Tuple
      55                 :            : 
      56                 :            :             The tuple is initialized to (0, 0)
      57                 :            :         */
      58                 :            :         B2I64Tuple()
      59                 :            :         :   mnX(0),
      60                 :            :             mnY(0)
      61                 :            :         {}
      62                 :            : 
      63                 :            :         /** Create a 2D Tuple
      64                 :            : 
      65                 :            :             @param fX
      66                 :            :             This parameter is used to initialize the X-coordinate
      67                 :            :             of the 2D Tuple.
      68                 :            : 
      69                 :            :             @param fY
      70                 :            :             This parameter is used to initialize the Y-coordinate
      71                 :            :             of the 2D Tuple.
      72                 :            :         */
      73                 :          0 :         B2I64Tuple(sal_Int64 fX, sal_Int64 fY)
      74                 :            :         :   mnX( fX ),
      75                 :          0 :             mnY( fY )
      76                 :          0 :         {}
      77                 :            : 
      78                 :            :         /** Create a copy of a 2D Tuple
      79                 :            : 
      80                 :            :             @param rTup
      81                 :            :             The 2D Tuple which will be copied.
      82                 :            :         */
      83                 :            :         B2I64Tuple(const B2I64Tuple& rTup)
      84                 :            :         :   mnX( rTup.mnX ),
      85                 :            :             mnY( rTup.mnY )
      86                 :            :         {}
      87                 :            : 
      88                 :          0 :         ~B2I64Tuple()
      89                 :          0 :         {}
      90                 :            : 
      91                 :            :         /// Get X-Coordinate of 2D Tuple
      92                 :          0 :         sal_Int64 getX() const
      93                 :            :         {
      94                 :          0 :             return mnX;
      95                 :            :         }
      96                 :            : 
      97                 :            :         /// Get Y-Coordinate of 2D Tuple
      98                 :          0 :         sal_Int64 getY() const
      99                 :            :         {
     100                 :          0 :             return mnY;
     101                 :            :         }
     102                 :            : 
     103                 :            :         /// Set X-Coordinate of 2D Tuple
     104                 :            :         void setX(sal_Int64 fX)
     105                 :            :         {
     106                 :            :             mnX = fX;
     107                 :            :         }
     108                 :            : 
     109                 :            :         /// Set Y-Coordinate of 2D Tuple
     110                 :            :         void setY(sal_Int64 fY)
     111                 :            :         {
     112                 :            :             mnY = fY;
     113                 :            :         }
     114                 :            : 
     115                 :            :         /// Array-access to 2D Tuple
     116                 :            :         const sal_Int64& operator[] (int nPos) const
     117                 :            :         {
     118                 :            :             // Here, normally one if(...) should be used. In the assumption that
     119                 :            :             // both sal_Int64 members can be accessed as an array a shortcut is used here.
     120                 :            :             // if(0 == nPos) return mnX; return mnY;
     121                 :            :             return *((&mnX) + nPos);
     122                 :            :         }
     123                 :            : 
     124                 :            :         /// Array-access to 2D Tuple
     125                 :            :         sal_Int64& operator[] (int nPos)
     126                 :            :         {
     127                 :            :             // Here, normally one if(...) should be used. In the assumption that
     128                 :            :             // both sal_Int64 members can be accessed as an array a shortcut is used here.
     129                 :            :             // if(0 == nPos) return mnX; return mnY;
     130                 :            :             return *((&mnX) + nPos);
     131                 :            :         }
     132                 :            : 
     133                 :            :         // operators
     134                 :            :         //////////////////////////////////////////////////////////////////////
     135                 :            : 
     136                 :            :         B2I64Tuple& operator+=( const B2I64Tuple& rTup )
     137                 :            :         {
     138                 :            :             mnX += rTup.mnX;
     139                 :            :             mnY += rTup.mnY;
     140                 :            :             return *this;
     141                 :            :         }
     142                 :            : 
     143                 :            :         B2I64Tuple& operator-=( const B2I64Tuple& rTup )
     144                 :            :         {
     145                 :            :             mnX -= rTup.mnX;
     146                 :            :             mnY -= rTup.mnY;
     147                 :            :             return *this;
     148                 :            :         }
     149                 :            : 
     150                 :            :         B2I64Tuple& operator/=( const B2I64Tuple& rTup )
     151                 :            :         {
     152                 :            :             mnX /= rTup.mnX;
     153                 :            :             mnY /= rTup.mnY;
     154                 :            :             return *this;
     155                 :            :         }
     156                 :            : 
     157                 :            :         B2I64Tuple& operator*=( const B2I64Tuple& rTup )
     158                 :            :         {
     159                 :            :             mnX *= rTup.mnX;
     160                 :            :             mnY *= rTup.mnY;
     161                 :            :             return *this;
     162                 :            :         }
     163                 :            : 
     164                 :            :         B2I64Tuple& operator*=(sal_Int64 t)
     165                 :            :         {
     166                 :            :             mnX *= t;
     167                 :            :             mnY *= t;
     168                 :            :             return *this;
     169                 :            :         }
     170                 :            : 
     171                 :            :         B2I64Tuple& operator/=(sal_Int64 t)
     172                 :            :         {
     173                 :            :             mnX /= t;
     174                 :            :             mnY /= t;
     175                 :            :             return *this;
     176                 :            :         }
     177                 :            : 
     178                 :            :         B2I64Tuple operator-(void) const
     179                 :            :         {
     180                 :            :             return B2I64Tuple(-mnX, -mnY);
     181                 :            :         }
     182                 :            : 
     183                 :            :         bool equalZero() const { return mnX == 0 && mnY == 0; }
     184                 :            : 
     185                 :            :         bool operator==( const B2I64Tuple& rTup ) const
     186                 :            :         {
     187                 :            :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     188                 :            :         }
     189                 :            : 
     190                 :            :         bool operator!=( const B2I64Tuple& rTup ) const
     191                 :            :         {
     192                 :            :             return !(*this == rTup);
     193                 :            :         }
     194                 :            : 
     195                 :            :         B2I64Tuple& operator=( const B2I64Tuple& rTup )
     196                 :            :         {
     197                 :            :             mnX = rTup.mnX;
     198                 :            :             mnY = rTup.mnY;
     199                 :            :             return *this;
     200                 :            :         }
     201                 :            :     };
     202                 :            : 
     203                 :            :     // external operators
     204                 :            :     //////////////////////////////////////////////////////////////////////////
     205                 :            : 
     206                 :            :     inline B2I64Tuple minimum(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     207                 :            :     {
     208                 :            :         B2I64Tuple aMin(
     209                 :            :             (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
     210                 :            :             (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY());
     211                 :            :         return aMin;
     212                 :            :     }
     213                 :            : 
     214                 :            :     inline B2I64Tuple maximum(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     215                 :            :     {
     216                 :            :         B2I64Tuple aMax(
     217                 :            :             (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
     218                 :            :             (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY());
     219                 :            :         return aMax;
     220                 :            :     }
     221                 :            : 
     222                 :            :     inline B2I64Tuple absolute(const B2I64Tuple& rTup)
     223                 :            :     {
     224                 :            :         B2I64Tuple aAbs(
     225                 :            :             (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(),
     226                 :            :             (0 > rTup.getY()) ? -rTup.getY() : rTup.getY());
     227                 :            :         return aAbs;
     228                 :            :     }
     229                 :            : 
     230                 :            :     inline B2DTuple interpolate(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2, double t)
     231                 :            :     {
     232                 :            :         B2DTuple aInt(
     233                 :            :             ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
     234                 :            :             ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY());
     235                 :            :         return aInt;
     236                 :            :     }
     237                 :            : 
     238                 :            :     inline B2DTuple average(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2)
     239                 :            :     {
     240                 :            :         B2DTuple aAvg(
     241                 :            :             (rOld1.getX() + rOld2.getX()) * 0.5,
     242                 :            :             (rOld1.getY() + rOld2.getY()) * 0.5);
     243                 :            :         return aAvg;
     244                 :            :     }
     245                 :            : 
     246                 :            :     inline B2DTuple average(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2, const B2I64Tuple& rOld3)
     247                 :            :     {
     248                 :            :         B2DTuple aAvg(
     249                 :            :             (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0),
     250                 :            :             (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0));
     251                 :            :         return aAvg;
     252                 :            :     }
     253                 :            : 
     254                 :            :     inline B2I64Tuple operator+(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     255                 :            :     {
     256                 :            :         B2I64Tuple aSum(rTupA);
     257                 :            :         aSum += rTupB;
     258                 :            :         return aSum;
     259                 :            :     }
     260                 :            : 
     261                 :            :     inline B2I64Tuple operator-(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     262                 :            :     {
     263                 :            :         B2I64Tuple aSub(rTupA);
     264                 :            :         aSub -= rTupB;
     265                 :            :         return aSub;
     266                 :            :     }
     267                 :            : 
     268                 :            :     inline B2I64Tuple operator/(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     269                 :            :     {
     270                 :            :         B2I64Tuple aDiv(rTupA);
     271                 :            :         aDiv /= rTupB;
     272                 :            :         return aDiv;
     273                 :            :     }
     274                 :            : 
     275                 :            :     inline B2I64Tuple operator*(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
     276                 :            :     {
     277                 :            :         B2I64Tuple aMul(rTupA);
     278                 :            :         aMul *= rTupB;
     279                 :            :         return aMul;
     280                 :            :     }
     281                 :            : 
     282                 :            :     inline B2I64Tuple operator*(const B2I64Tuple& rTup, sal_Int64 t)
     283                 :            :     {
     284                 :            :         B2I64Tuple aNew(rTup);
     285                 :            :         aNew *= t;
     286                 :            :         return aNew;
     287                 :            :     }
     288                 :            : 
     289                 :            :     inline B2I64Tuple operator*(sal_Int64 t, const B2I64Tuple& rTup)
     290                 :            :     {
     291                 :            :         B2I64Tuple aNew(rTup);
     292                 :            :         aNew *= t;
     293                 :            :         return aNew;
     294                 :            :     }
     295                 :            : 
     296                 :            :     inline B2I64Tuple operator/(const B2I64Tuple& rTup, sal_Int64 t)
     297                 :            :     {
     298                 :            :         B2I64Tuple aNew(rTup);
     299                 :            :         aNew /= t;
     300                 :            :         return aNew;
     301                 :            :     }
     302                 :            : 
     303                 :            :     inline B2I64Tuple operator/(sal_Int64 t, const B2I64Tuple& rTup)
     304                 :            :     {
     305                 :            :         B2I64Tuple aNew(t, t);
     306                 :            :         B2I64Tuple aTmp(rTup);
     307                 :            :         aNew /= aTmp;
     308                 :            :         return aNew;
     309                 :            :     }
     310                 :            : } // end of namespace basegfx
     311                 :            : 
     312                 :            : #endif /* _BGFX_TUPLE_B2I64TUPLE_HXX */
     313                 :            : 
     314                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10