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

Generated by: LCOV version 1.10