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

Generated by: LCOV version 1.10