LCOV - code coverage report
Current view: top level - include/basegfx/tuple - b2ituple.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 55 55 100.0 %
Date: 2015-06-13 12:38:46 Functions: 18 18 100.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     1135164 :         B2ITuple()
      50             :         :   mnX(0),
      51     1135164 :             mnY(0)
      52     1135164 :         {}
      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  1867478100 :         B2ITuple(sal_Int32 fX, sal_Int32 fY)
      65             :         :   mnX( fX ),
      66  1867478100 :             mnY( fY )
      67  1867478100 :         {}
      68             : 
      69             :         /** Create a copy of a 2D Tuple
      70             : 
      71             :             @param rTup
      72             :             The 2D Tuple which will be copied.
      73             :         */
      74    40597934 :         B2ITuple(const B2ITuple& rTup)
      75             :         :   mnX( rTup.mnX ),
      76    40597934 :             mnY( rTup.mnY )
      77    40597934 :         {}
      78             : 
      79  1909191575 :         ~B2ITuple()
      80  1909191575 :         {}
      81             : 
      82             :         /// Get X-Coordinate of 2D Tuple
      83  3719195771 :         sal_Int32 getX() const
      84             :         {
      85  3719195771 :             return mnX;
      86             :         }
      87             : 
      88             :         /// Get Y-Coordinate of 2D Tuple
      89  3719555910 :         sal_Int32 getY() const
      90             :         {
      91  3719555910 :             return mnY;
      92             :         }
      93             : 
      94             :         /// Set X-Coordinate of 2D Tuple
      95           3 :         void setX(sal_Int32 fX)
      96             :         {
      97           3 :             mnX = fX;
      98           3 :         }
      99             : 
     100             :         /// Set Y-Coordinate of 2D Tuple
     101           3 :         void setY(sal_Int32 fY)
     102             :         {
     103           3 :             mnY = fY;
     104           3 :         }
     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          52 :         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          52 :             return *((&mnX) + nPos);
     122             :         }
     123             : 
     124             :         // operators
     125             : 
     126             : 
     127     7225856 :         B2ITuple& operator+=( const B2ITuple& rTup )
     128             :         {
     129     7225856 :             mnX += rTup.mnX;
     130     7225856 :             mnY += rTup.mnY;
     131     7225856 :             return *this;
     132             :         }
     133             : 
     134     7501135 :         B2ITuple& operator-=( const B2ITuple& rTup )
     135             :         {
     136     7501135 :             mnX -= rTup.mnX;
     137     7501135 :             mnY -= rTup.mnY;
     138     7501135 :             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          25 :         B2ITuple& operator*=(sal_Int32 t)
     156             :         {
     157          25 :             mnX *= t;
     158          25 :             mnY *= t;
     159          25 :             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      226640 :         bool operator==( const B2ITuple& rTup ) const
     180             :         {
     181      226640 :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     182             :         }
     183             : 
     184      226636 :         bool operator!=( const B2ITuple& rTup ) const
     185             :         {
     186      226636 :             return !(*this == rTup);
     187             :         }
     188             : 
     189     2525493 :         B2ITuple& operator=( const B2ITuple& rTup )
     190             :         {
     191     2525493 :             mnX = rTup.mnX;
     192     2525493 :             mnY = rTup.mnY;
     193     2525493 :             return *this;
     194             :         }
     195             :     };
     196             : 
     197             :     // external operators
     198             : 
     199             : 
     200             : 
     201     5613835 :     inline B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB)
     202             :     {
     203     5613835 :         B2ITuple aSum(rTupA);
     204     5613835 :         aSum += rTupB;
     205     5613835 :         return aSum;
     206             :     }
     207             : 
     208     7501135 :     inline B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB)
     209             :     {
     210     7501135 :         B2ITuple aSub(rTupA);
     211     7501135 :         aSub -= rTupB;
     212     7501135 :         return aSub;
     213             :     }
     214             : 
     215             :     inline B2ITuple operator/(const B2ITuple& rTupA, const B2ITuple& rTupB)
     216             :     {
     217             :         B2ITuple aDiv(rTupA);
     218             :         aDiv /= rTupB;
     219             :         return aDiv;
     220             :     }
     221             : 
     222             :     inline B2ITuple operator*(const B2ITuple& rTupA, const B2ITuple& rTupB)
     223             :     {
     224             :         B2ITuple aMul(rTupA);
     225             :         aMul *= rTupB;
     226             :         return aMul;
     227             :     }
     228             : 
     229             :     inline B2ITuple operator*(const B2ITuple& rTup, sal_Int32 t)
     230             :     {
     231             :         B2ITuple aNew(rTup);
     232             :         aNew *= t;
     233             :         return aNew;
     234             :     }
     235             : 
     236          25 :     inline B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup)
     237             :     {
     238          25 :         B2ITuple aNew(rTup);
     239          25 :         aNew *= t;
     240          25 :         return aNew;
     241             :     }
     242             : 
     243             :     inline B2ITuple operator/(const B2ITuple& rTup, sal_Int32 t)
     244             :     {
     245             :         B2ITuple aNew(rTup);
     246             :         aNew /= t;
     247             :         return aNew;
     248             :     }
     249             : 
     250             :     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.11