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

Generated by: LCOV version 1.10