LCOV - code coverage report
Current view: top level - include/basegfx/matrix - b2dhommatrixtools.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 36 0.0 %
Date: 2014-04-14 Functions: 0 23 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_MATRIX_B2DHOMMATRIXTOOLS_HXX
      21             : #define INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIXTOOLS_HXX
      22             : 
      23             : #include <sal/types.h>
      24             : #include <basegfx/matrix/b2dhommatrix.hxx>
      25             : #include <basegfx/vector/b2dvector.hxx>
      26             : #include <basegfx/range/b2drange.hxx>
      27             : #include <basegfx/basegfxdllapi.h>
      28             : 
      29             : 
      30             : 
      31             : 
      32             : namespace basegfx
      33             : {
      34             :     namespace tools
      35             :     {
      36             :         /** If the rotation angle is an approximate multiple of pi/2,
      37             :             force fSin/fCos to -1/0/1, to maintain orthogonality (which
      38             :             might also be advantageous for the other cases, but: for
      39             :             multiples of pi/2, the exact values _can_ be attained. It
      40             :             would be largely unintuitive, if a 180 degrees rotation
      41             :             would introduce slight roundoff errors, instead of exactly
      42             :             mirroring the coordinate system)
      43             :          */
      44             :         BASEGFX_DLLPUBLIC void createSinCosOrthogonal(double& o_rSin, double& rCos, double fRadiant);
      45             : 
      46             :         /** Tooling methods for on-the-fly matrix generation e.g. for inline
      47             :             multiplications
      48             :          */
      49             :         BASEGFX_DLLPUBLIC B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY);
      50             :         BASEGFX_DLLPUBLIC B2DHomMatrix createShearXB2DHomMatrix(double fShearX);
      51             :         BASEGFX_DLLPUBLIC B2DHomMatrix createShearYB2DHomMatrix(double fShearY);
      52             :         BASEGFX_DLLPUBLIC B2DHomMatrix createRotateB2DHomMatrix(double fRadiant);
      53             :         BASEGFX_DLLPUBLIC B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY);
      54             : 
      55             :         /// inline versions for parameters as tuples
      56           0 :         inline B2DHomMatrix createScaleB2DHomMatrix(const B2DTuple& rScale)
      57             :         {
      58           0 :             return createScaleB2DHomMatrix(rScale.getX(), rScale.getY());
      59             :         }
      60             : 
      61           0 :         inline B2DHomMatrix createTranslateB2DHomMatrix(const B2DTuple& rTranslate)
      62             :         {
      63           0 :             return createTranslateB2DHomMatrix(rTranslate.getX(), rTranslate.getY());
      64             :         }
      65             : 
      66             :         /** Tooling methods for faster completely combined matrix creation
      67             :             when scale, shearX, rotation and translation needs to be done in
      68             :             exactly that order. It's faster since it direcly calculates
      69             :             each matrix value based on a symbolic calculation of the three
      70             :             matrix multiplications.
      71             :             Inline versions for parameters as tuples added, too.
      72             :          */
      73             :         BASEGFX_DLLPUBLIC B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(
      74             :             double fScaleX, double fScaleY,
      75             :             double fShearX,
      76             :             double fRadiant,
      77             :             double fTranslateX, double fTranslateY);
      78           0 :         inline B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(
      79             :             const B2DTuple& rScale,
      80             :             double fShearX,
      81             :             double fRadiant,
      82             :             const B2DTuple& rTranslate)
      83             :         {
      84             :             return createScaleShearXRotateTranslateB2DHomMatrix(
      85             :                 rScale.getX(), rScale.getY(),
      86             :                 fShearX,
      87             :                 fRadiant,
      88           0 :                 rTranslate.getX(), rTranslate.getY());
      89             :         }
      90             : 
      91             :         BASEGFX_DLLPUBLIC B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(
      92             :             double fShearX,
      93             :             double fRadiant,
      94             :             double fTranslateX, double fTranslateY);
      95           0 :         inline B2DHomMatrix createShearXRotateTranslateB2DHomMatrix(
      96             :             double fShearX,
      97             :             double fRadiant,
      98             :             const B2DTuple& rTranslate)
      99             :         {
     100             :             return createShearXRotateTranslateB2DHomMatrix(
     101             :                 fShearX,
     102             :                 fRadiant,
     103           0 :                 rTranslate.getX(), rTranslate.getY());
     104             :         }
     105             : 
     106             :         BASEGFX_DLLPUBLIC B2DHomMatrix createScaleTranslateB2DHomMatrix(
     107             :             double fScaleX, double fScaleY,
     108             :             double fTranslateX, double fTranslateY);
     109           0 :         inline B2DHomMatrix createScaleTranslateB2DHomMatrix(
     110             :             const B2DTuple& rScale,
     111             :             const B2DTuple& rTranslate)
     112             :         {
     113             :             return createScaleTranslateB2DHomMatrix(
     114             :                 rScale.getX(), rScale.getY(),
     115           0 :                 rTranslate.getX(), rTranslate.getY());
     116             :         }
     117             : 
     118             :         /// special for the often used case of rotation around a point
     119             :         BASEGFX_DLLPUBLIC B2DHomMatrix createRotateAroundPoint(
     120             :             double fPointX, double fPointY,
     121             :             double fRadiant);
     122           0 :         inline B2DHomMatrix createRotateAroundPoint(
     123             :             const B2DTuple& rPoint,
     124             :             double fRadiant)
     125             :         {
     126             :             return createRotateAroundPoint(
     127             :                 rPoint.getX(), rPoint.getY(),
     128           0 :                 fRadiant);
     129             :         }
     130             : 
     131             :         /// special for the case to map from source range to target range
     132             :         BASEGFX_DLLPUBLIC B2DHomMatrix createSourceRangeTargetRangeTransform(
     133             :             const B2DRange& rSourceRange,
     134             :             const B2DRange& rTargetRange);
     135             : 
     136             :     } // end of namespace tools
     137             : } // end of namespace basegfx
     138             : 
     139             : 
     140             : 
     141             : namespace basegfx
     142             : {
     143             :     namespace tools
     144             :     {
     145           0 :         class BASEGFX_DLLPUBLIC B2DHomMatrixBufferedDecompose
     146             :         {
     147             :         private:
     148             :             B2DVector              maScale;
     149             :             B2DVector              maTranslate;
     150             :             double                 mfRotate;
     151             :             double                 mfShearX;
     152             : 
     153             :         public:
     154           0 :             B2DHomMatrixBufferedDecompose(const B2DHomMatrix& rB2DHomMatrix = B2DHomMatrix())
     155             :             :   maScale(),
     156             :                 maTranslate(),
     157             :                 mfRotate(0.0),
     158           0 :                 mfShearX(0.0)
     159             :             {
     160           0 :                 rB2DHomMatrix.decompose(maScale, maTranslate, mfRotate, mfShearX);
     161           0 :             }
     162             : 
     163             :             // data access
     164           0 :             B2DHomMatrix getB2DHomMatrix() const
     165             :             {
     166             :                 return createScaleShearXRotateTranslateB2DHomMatrix(
     167           0 :                     maScale, mfShearX, mfRotate, maTranslate);
     168             :             }
     169             : 
     170           0 :             const B2DVector& getScale() const { return maScale; }
     171           0 :             const B2DVector& getTranslate() const { return maTranslate; }
     172           0 :             double getRotate() const { return mfRotate; }
     173           0 :             double getShearX() const { return mfShearX; }
     174             :         };
     175             :     } // end of namespace tools
     176             : } // end of namespace basegfx
     177             : 
     178             : 
     179             : 
     180             : namespace basegfx
     181             : {
     182             :     namespace tools
     183             :     {
     184           0 :         class BASEGFX_DLLPUBLIC B2DHomMatrixBufferedOnDemandDecompose
     185             :         {
     186             :         private:
     187             :             B2DHomMatrix           maB2DHomMatrix;
     188             :             B2DVector              maScale;
     189             :             B2DVector              maTranslate;
     190             :             double                 mfRotate;
     191             :             double                 mfShearX;
     192             : 
     193             :             // bitfield
     194             :             bool                   mbDecomposed : 1;
     195             : 
     196           0 :             void impCheckDecompose()
     197             :             {
     198           0 :                 if(!mbDecomposed)
     199             :                 {
     200           0 :                     maB2DHomMatrix.decompose(maScale, maTranslate, mfRotate, mfShearX);
     201           0 :                     mbDecomposed = true;
     202             :                 }
     203           0 :             }
     204             : 
     205             :         public:
     206           0 :             B2DHomMatrixBufferedOnDemandDecompose(const B2DHomMatrix& rB2DHomMatrix = B2DHomMatrix())
     207             :             :   maB2DHomMatrix(rB2DHomMatrix),
     208             :                 maScale(),
     209             :                 maTranslate(),
     210             :                 mfRotate(0.0),
     211             :                 mfShearX(0.0),
     212           0 :                 mbDecomposed(false)
     213             :             {
     214           0 :             }
     215             : 
     216             :             // data access
     217           0 :             const B2DHomMatrix& getB2DHomMatrix() const { return maB2DHomMatrix; }
     218           0 :             const B2DVector& getScale() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return maScale; }
     219           0 :             const B2DVector& getTranslate() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return maTranslate; }
     220           0 :             double getRotate() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return mfRotate; }
     221             :             double getShearX() const { const_cast< B2DHomMatrixBufferedOnDemandDecompose* >(this)->impCheckDecompose(); return mfShearX; }
     222             :         };
     223             :     } // end of namespace tools
     224             : 
     225             : } // end of namespace basegfx
     226             : 
     227             : 
     228             : 
     229             : #endif // INCLUDED_BASEGFX_MATRIX_B2DHOMMATRIXTOOLS_HXX
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10