LCOV - code coverage report
Current view: top level - include/basegfx/tuple - b2ituple.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 53 84.9 %
Date: 2014-11-03 Functions: 15 17 88.2 %
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     1830530 :         B2ITuple()
      50             :         :   mnX(0),
      51     1830530 :             mnY(0)
      52     1830530 :         {}
      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   181264206 :         B2ITuple(sal_Int32 fX, sal_Int32 fY)
      65             :         :   mnX( fX ),
      66   181264206 :             mnY( fY )
      67   181264206 :         {}
      68             : 
      69             :         /** Create a copy of a 2D Tuple
      70             : 
      71             :             @param rTup
      72             :             The 2D Tuple which will be copied.
      73             :         */
      74    54393952 :         B2ITuple(const B2ITuple& rTup)
      75             :         :   mnX( rTup.mnX ),
      76    54393952 :             mnY( rTup.mnY )
      77    54393952 :         {}
      78             : 
      79   237464759 :         ~B2ITuple()
      80   237464759 :         {}
      81             : 
      82             :         /// Get X-Coordinate of 2D Tuple
      83   329682588 :         sal_Int32 getX() const
      84             :         {
      85   329682588 :             return mnX;
      86             :         }
      87             : 
      88             :         /// Get Y-Coordinate of 2D Tuple
      89   328927023 :         sal_Int32 getY() const
      90             :         {
      91   328927023 :             return mnY;
      92             :         }
      93             : 
      94             :         /// Set X-Coordinate of 2D Tuple
      95           4 :         void setX(sal_Int32 fX)
      96             :         {
      97           4 :             mnX = fX;
      98           4 :         }
      99             : 
     100             :         /// Set Y-Coordinate of 2D Tuple
     101           4 :         void setY(sal_Int32 fY)
     102             :         {
     103           4 :             mnY = fY;
     104           4 :         }
     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    14809189 :         B2ITuple& operator+=( const B2ITuple& rTup )
     128             :         {
     129    14809189 :             mnX += rTup.mnX;
     130    14809189 :             mnY += rTup.mnY;
     131    14809189 :             return *this;
     132             :         }
     133             : 
     134    13544376 :         B2ITuple& operator-=( const B2ITuple& rTup )
     135             :         {
     136    13544376 :             mnX -= rTup.mnX;
     137    13544376 :             mnY -= rTup.mnY;
     138    13544376 :             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      773104 :         bool operator==( const B2ITuple& rTup ) const
     180             :         {
     181      773104 :             return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
     182             :         }
     183             : 
     184      773096 :         bool operator!=( const B2ITuple& rTup ) const
     185             :         {
     186      773096 :             return !(*this == rTup);
     187             :         }
     188             : 
     189     4200644 :         B2ITuple& operator=( const B2ITuple& rTup )
     190             :         {
     191     4200644 :             mnX = rTup.mnX;
     192     4200644 :             mnY = rTup.mnY;
     193     4200644 :             return *this;
     194             :         }
     195             :     };
     196             : 
     197             :     // external operators
     198             : 
     199             : 
     200             : 
     201    11135826 :     inline B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB)
     202             :     {
     203    11135826 :         B2ITuple aSum(rTupA);
     204    11135826 :         aSum += rTupB;
     205    11135826 :         return aSum;
     206             :     }
     207             : 
     208    13544376 :     inline B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB)
     209             :     {
     210    13544376 :         B2ITuple aSub(rTupA);
     211    13544376 :         aSub -= rTupB;
     212    13544376 :         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           0 :     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             :     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.10