LCOV - code coverage report
Current view: top level - include/basegfx/tuple - b2ituple.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 53 0.0 %
Date: 2014-04-14 Functions: 0 17 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_B2ITUPLE_HXX
      21             : #define INCLUDED_BASEGFX_TUPLE_B2ITUPLE_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <basegfx/numeric/ftools.hxx>
      25             : #include <algorithm>
      26             : #include <basegfx/basegfxdllapi.h>
      27             : 
      28             : namespace basegfx
      29             : {
      30             :     /** Base class for all Points/Vectors with two sal_Int32 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_Int32 values
      37             :     */
      38             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B2ITuple
      39             :     {
      40             :     protected:
      41             :         sal_Int32                                       mnX;
      42             :         sal_Int32                                       mnY;
      43             : 
      44             :     public:
      45             :         /** Create a 2D Tuple
      46             : 
      47             :             The tuple is initialized to (0, 0)
      48             :         */
      49           0 :         B2ITuple()
      50             :         :   mnX(0),
      51           0 :             mnY(0)
      52           0 :         {}
      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 :         B2ITuple(sal_Int32 fX, sal_Int32 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           0 :         B2ITuple(const B2ITuple& rTup)
      75             :         :   mnX( rTup.mnX ),
      76           0 :             mnY( rTup.mnY )
      77           0 :         {}
      78             : 
      79           0 :         ~B2ITuple()
      80           0 :         {}
      81             : 
      82             :         /// Get X-Coordinate of 2D Tuple
      83           0 :         sal_Int32 getX() const
      84             :         {
      85           0 :             return mnX;
      86             :         }
      87             : 
      88             :         /// Get Y-Coordinate of 2D Tuple
      89           0 :         sal_Int32 getY() const
      90             :         {
      91           0 :             return mnY;
      92             :         }
      93             : 
      94             :         /// Set X-Coordinate of 2D Tuple
      95           0 :         void setX(sal_Int32 fX)
      96             :         {
      97           0 :             mnX = fX;
      98           0 :         }
      99             : 
     100             :         /// Set Y-Coordinate of 2D Tuple
     101           0 :         void setY(sal_Int32 fY)
     102             :         {
     103           0 :             mnY = fY;
     104           0 :         }
     105             : 
     106             :         /// Array-access to 2D Tuple
     107             :         const sal_Int32& operator[] (int nPos) const
     108             :         {
     109             :             // Here, normally one if(...) should be used. In the assumption that
     110             :             // both sal_Int32 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_Int32& operator[] (int nPos)
     117             :         {
     118             :             // Here, normally one if(...) should be used. In the assumption that
     119             :             // both sal_Int32 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           0 :         B2ITuple& operator+=( const B2ITuple& rTup )
     128             :         {
     129           0 :             mnX += rTup.mnX;
     130           0 :             mnY += rTup.mnY;
     131           0 :             return *this;
     132             :         }
     133             : 
     134           0 :         B2ITuple& operator-=( const B2ITuple& rTup )
     135             :         {
     136           0 :             mnX -= rTup.mnX;
     137           0 :             mnY -= rTup.mnY;
     138           0 :             return *this;
     139             :         }
     140             : 
     141             :         B2ITuple& operator/=( const B2ITuple& rTup )
     142             :         {
     143             :             mnX /= rTup.mnX;
     144             :             mnY /= rTup.mnY;
     145             :             return *this;
     146             :         }
     147             : 
     148             :         B2ITuple& operator*=( const B2ITuple& rTup )
     149             :         {
     150             :             mnX *= rTup.mnX;
     151             :             mnY *= rTup.mnY;
     152             :             return *this;
     153             :         }
     154             : 
     155           0 :         B2ITuple& operator*=(sal_Int32 t)
     156             :         {
     157           0 :             mnX *= t;
     158           0 :             mnY *= t;
     159           0 :             return *this;
     160             :         }
     161             : 
     162             :         B2ITuple& operator/=(sal_Int32 t)
     163             :         {
     164             :             mnX /= t;
     165             :             mnY /= t;
     166             :             return *this;
     167             :         }
     168             : 
     169             :         B2ITuple operator-(void) const
     170             :         {
     171             :             return B2ITuple(-mnX, -mnY);
     172             :         }
     173             : 
     174             :         bool equalZero() const
     175             :         {
     176             :             return mnX == 0 && mnY == 0;
     177             :         }
     178             : 
     179           0 :         bool operator==( const B2ITuple& rTup ) const
     180             :         {
     181           0 :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     182             :         }
     183             : 
     184           0 :         bool operator!=( const B2ITuple& rTup ) const
     185             :         {
     186           0 :             return !(*this == rTup);
     187             :         }
     188             : 
     189           0 :         B2ITuple& operator=( const B2ITuple& rTup )
     190             :         {
     191           0 :             mnX = rTup.mnX;
     192           0 :             mnY = rTup.mnY;
     193           0 :             return *this;
     194             :         }
     195             :     };
     196             : 
     197             :     // external operators
     198             : 
     199             : 
     200             : 
     201           0 :     BASEGFX_DLLPUBLIC inline B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB)
     202             :     {
     203           0 :         B2ITuple aSum(rTupA);
     204           0 :         aSum += rTupB;
     205           0 :         return aSum;
     206             :     }
     207             : 
     208           0 :     BASEGFX_DLLPUBLIC inline B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB)
     209             :     {
     210           0 :         B2ITuple aSub(rTupA);
     211           0 :         aSub -= rTupB;
     212           0 :         return aSub;
     213             :     }
     214             : 
     215             :     BASEGFX_DLLPUBLIC inline B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB)
     216             :     {
     217             :         B2ITuple aDiv(rTupA);
     218             :         aDiv /= rTupB;
     219             :         return aDiv;
     220             :     }
     221             : 
     222             :     BASEGFX_DLLPUBLIC inline B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB)
     223             :     {
     224             :         B2ITuple aMul(rTupA);
     225             :         aMul *= rTupB;
     226             :         return aMul;
     227             :     }
     228             : 
     229             :     BASEGFX_DLLPUBLIC inline B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t)
     230             :     {
     231             :         B2ITuple aNew(rTup);
     232             :         aNew *= t;
     233             :         return aNew;
     234             :     }
     235             : 
     236           0 :     BASEGFX_DLLPUBLIC inline B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup)
     237             :     {
     238           0 :         B2ITuple aNew(rTup);
     239           0 :         aNew *= t;
     240           0 :         return aNew;
     241             :     }
     242             : 
     243             :     BASEGFX_DLLPUBLIC inline B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t)
     244             :     {
     245             :         B2ITuple aNew(rTup);
     246             :         aNew /= t;
     247             :         return aNew;
     248             :     }
     249             : 
     250             :     BASEGFX_DLLPUBLIC inline B2ITuple operator/(sal_Int32 t, const B2ITuple& rTup)
     251             :     {
     252             :         B2ITuple aNew(t, t);
     253             :         B2ITuple aTmp(rTup);
     254             :         aNew /= aTmp;
     255             :         return aNew;
     256             :     }
     257             : 
     258             : } // end of namespace basegfx
     259             : 
     260             : #endif // INCLUDED_BASEGFX_TUPLE_B2ITUPLE_HXX
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10