LCOV - code coverage report
Current view: top level - basegfx/source/vector - b2dvector.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 76 76 100.0 %
Date: 2014-11-03 Functions: 13 13 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             : #include <basegfx/vector/b2dvector.hxx>
      21             : #include <basegfx/matrix/b2dhommatrix.hxx>
      22             : #include <basegfx/numeric/ftools.hxx>
      23             : 
      24             : namespace basegfx
      25             : {
      26     1759021 :     B2DVector& B2DVector::normalize()
      27             :     {
      28     1759021 :         double fLen(scalar(*this));
      29             : 
      30     1759021 :         if(fTools::equalZero(fLen))
      31             :         {
      32        9659 :             mfX = 0.0;
      33        9659 :             mfY = 0.0;
      34             :         }
      35             :         else
      36             :         {
      37     1749362 :             const double fOne(1.0);
      38             : 
      39     1749362 :             if(!fTools::equal(fOne, fLen))
      40             :             {
      41     1652377 :                 fLen = sqrt(fLen);
      42             : 
      43     1652377 :                 if(!fTools::equalZero(fLen))
      44             :                 {
      45     1652377 :                     mfX /= fLen;
      46     1652377 :                     mfY /= fLen;
      47             :                 }
      48             :             }
      49             :         }
      50             : 
      51     1759021 :         return *this;
      52             :     }
      53             : 
      54      134616 :     B2DVector& B2DVector::operator=( const B2DTuple& rVec )
      55             :     {
      56      134616 :         mfX = rVec.getX();
      57      134616 :         mfY = rVec.getY();
      58      134616 :         return *this;
      59             :     }
      60             : 
      61      665392 :     double B2DVector::getLength() const
      62             :     {
      63      665392 :         if(fTools::equalZero(mfX))
      64             :         {
      65      153314 :             return fabs(mfY);
      66             :         }
      67      512078 :         else if(fTools::equalZero(mfY))
      68             :         {
      69      183057 :             return fabs(mfX);
      70             :         }
      71             : 
      72      329021 :         return hypot( mfX, mfY );
      73             :     }
      74             : 
      75      334667 :     double B2DVector::angle( const B2DVector& rVec ) const
      76             :     {
      77      334667 :         return atan2(mfX * rVec.getY() - mfY * rVec.getX(),
      78      669334 :             mfX * rVec.getX() + mfY * rVec.getY());
      79             :     }
      80             : 
      81         624 :     const B2DVector& B2DVector::getEmptyVector()
      82             :     {
      83         624 :         return static_cast<const B2DVector&>( B2DTuple::getEmptyTuple() );
      84             :     }
      85             : 
      86      857493 :     B2DVector& B2DVector::operator*=( const B2DHomMatrix& rMat )
      87             :     {
      88      857493 :         const double fTempX( rMat.get(0,0)*mfX +
      89      857493 :                             rMat.get(0,1)*mfY );
      90      857493 :         const double fTempY( rMat.get(1,0)*mfX +
      91      857493 :                             rMat.get(1,1)*mfY );
      92      857493 :         mfX = fTempX;
      93      857493 :         mfY = fTempY;
      94             : 
      95      857493 :         return *this;
      96             :     }
      97             : 
      98       37830 :     B2DVector& B2DVector::setLength(double fLen)
      99             :     {
     100       37830 :         double fLenNow(scalar(*this));
     101             : 
     102       37830 :         if(!fTools::equalZero(fLenNow))
     103             :         {
     104       36990 :             const double fOne(1.0);
     105             : 
     106       36990 :             if(!fTools::equal(fOne, fLenNow))
     107             :             {
     108       36840 :                 fLen /= sqrt(fLenNow);
     109             :             }
     110             : 
     111       36990 :             mfX *= fLen;
     112       36990 :             mfY *= fLen;
     113             :         }
     114             : 
     115       37830 :         return *this;
     116             :     }
     117             : 
     118     3917872 :     bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB )
     119             :     {
     120     3917872 :         const double fValA(rVecA.getX() * rVecB.getY());
     121     3917872 :         const double fValB(rVecA.getY() * rVecB.getX());
     122             : 
     123     3917872 :         return fTools::equal(fValA, fValB);
     124             :     }
     125             : 
     126       34238 :     B2VectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB )
     127             :     {
     128       34238 :         double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
     129             : 
     130       34238 :         if(fTools::equalZero(fVal))
     131             :         {
     132        5648 :             return ORIENTATION_NEUTRAL;
     133             :         }
     134             : 
     135       28590 :         if(fVal > 0.0)
     136             :         {
     137       23424 :             return ORIENTATION_POSITIVE;
     138             :         }
     139             :         else
     140             :         {
     141        5166 :             return ORIENTATION_NEGATIVE;
     142             :         }
     143             :     }
     144             : 
     145       55114 :     B2DVector getPerpendicular( const B2DVector& rNormalizedVec )
     146             :     {
     147       55114 :         B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
     148       55114 :         return aPerpendicular;
     149             :     }
     150             : 
     151       67168 :     B2DVector getNormalizedPerpendicular( const B2DVector& rVec )
     152             :     {
     153       67168 :         B2DVector aPerpendicular(rVec);
     154       67168 :         aPerpendicular.normalize();
     155       67168 :         const double aTemp(-aPerpendicular.getY());
     156       67168 :         aPerpendicular.setY(aPerpendicular.getX());
     157       67168 :         aPerpendicular.setX(aTemp);
     158       67168 :         return aPerpendicular;
     159             :     }
     160             : 
     161      857493 :     B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec )
     162             :     {
     163      857493 :         B2DVector aRes( rVec );
     164      857493 :         return aRes*=rMat;
     165             :     }
     166             : 
     167      140622 :     B2VectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector )
     168             :     {
     169      140622 :         if(rBackVector.equalZero() || rForwardVector.equalZero())
     170             :         {
     171       35160 :             return CONTINUITY_NONE;
     172             :         }
     173             : 
     174      105462 :         if(fTools::equal(rBackVector.getX(), -rForwardVector.getX()) && fTools::equal(rBackVector.getY(), -rForwardVector.getY()))
     175             :         {
     176             :             // same direction and same length -> C2
     177       57948 :             return CONTINUITY_C2;
     178             :         }
     179             : 
     180       47514 :         if(areParallel(rBackVector, rForwardVector) && rBackVector.scalar(rForwardVector) < 0.0)
     181             :         {
     182             :             // parallel and opposite direction -> C1
     183       15538 :             return CONTINUITY_C1;
     184             :         }
     185             : 
     186       31976 :         return CONTINUITY_NONE;
     187             :     }
     188             : } // end of namespace basegfx
     189             : 
     190             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10