LCOV - code coverage report
Current view: top level - basegfx/source/vector - b2dvector.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 80 80 100.0 %
Date: 2014-04-11 Functions: 15 15 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     1720678 :     B2DVector& B2DVector::normalize()
      27             :     {
      28     1720678 :         double fLen(scalar(*this));
      29             : 
      30     1720678 :         if(fTools::equalZero(fLen))
      31             :         {
      32        9013 :             mfX = 0.0;
      33        9013 :             mfY = 0.0;
      34             :         }
      35             :         else
      36             :         {
      37     1711665 :             const double fOne(1.0);
      38             : 
      39     1711665 :             if(!fTools::equal(fOne, fLen))
      40             :             {
      41     1647094 :                 fLen = sqrt(fLen);
      42             : 
      43     1647094 :                 if(!fTools::equalZero(fLen))
      44             :                 {
      45     1647094 :                     mfX /= fLen;
      46     1647094 :                     mfY /= fLen;
      47             :                 }
      48             :             }
      49             :         }
      50             : 
      51     1720678 :         return *this;
      52             :     }
      53             : 
      54       85121 :     B2DVector& B2DVector::operator=( const B2DTuple& rVec )
      55             :     {
      56       85121 :         mfX = rVec.getX();
      57       85121 :         mfY = rVec.getY();
      58       85121 :         return *this;
      59             :     }
      60             : 
      61             : 
      62      612399 :     double B2DVector::getLength() const
      63             :     {
      64      612399 :         if(fTools::equalZero(mfX))
      65             :         {
      66      146203 :             return fabs(mfY);
      67             :         }
      68      466196 :         else if(fTools::equalZero(mfY))
      69             :         {
      70      170802 :             return fabs(mfX);
      71             :         }
      72             : 
      73      295394 :         return hypot( mfX, mfY );
      74             :     }
      75             : 
      76     1758713 :     double B2DVector::scalar( const B2DVector& rVec ) const
      77             :     {
      78     1758713 :         return((mfX * rVec.mfX) + (mfY * rVec.mfY));
      79             :     }
      80             : 
      81      698231 :     double B2DVector::cross( const B2DVector& rVec ) const
      82             :     {
      83      698231 :         return(mfX * rVec.getY() - mfY * rVec.getX());
      84             :     }
      85             : 
      86       80665 :     double B2DVector::angle( const B2DVector& rVec ) const
      87             :     {
      88       80665 :         return atan2(mfX * rVec.getY() - mfY * rVec.getX(),
      89      161330 :             mfX * rVec.getX() + mfY * rVec.getY());
      90             :     }
      91             : 
      92         565 :     const B2DVector& B2DVector::getEmptyVector()
      93             :     {
      94         565 :         return (const B2DVector&) B2DTuple::getEmptyTuple();
      95             :     }
      96             : 
      97      581714 :     B2DVector& B2DVector::operator*=( const B2DHomMatrix& rMat )
      98             :     {
      99      581714 :         const double fTempX( rMat.get(0,0)*mfX +
     100      581714 :                             rMat.get(0,1)*mfY );
     101      581714 :         const double fTempY( rMat.get(1,0)*mfX +
     102      581714 :                             rMat.get(1,1)*mfY );
     103      581714 :         mfX = fTempX;
     104      581714 :         mfY = fTempY;
     105             : 
     106      581714 :         return *this;
     107             :     }
     108             : 
     109       14352 :     B2DVector& B2DVector::setLength(double fLen)
     110             :     {
     111       14352 :         double fLenNow(scalar(*this));
     112             : 
     113       14352 :         if(!fTools::equalZero(fLenNow))
     114             :         {
     115       13835 :             const double fOne(1.0);
     116             : 
     117       13835 :             if(!fTools::equal(fOne, fLenNow))
     118             :             {
     119       13810 :                 fLen /= sqrt(fLenNow);
     120             :             }
     121             : 
     122       13835 :             mfX *= fLen;
     123       13835 :             mfY *= fLen;
     124             :         }
     125             : 
     126       14352 :         return *this;
     127             :     }
     128             : 
     129     3917235 :     bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB )
     130             :     {
     131     3917235 :         const double fValA(rVecA.getX() * rVecB.getY());
     132     3917235 :         const double fValB(rVecA.getY() * rVecB.getX());
     133             : 
     134     3917235 :         return fTools::equal(fValA, fValB);
     135             :     }
     136             : 
     137        9704 :     B2VectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB )
     138             :     {
     139        9704 :         double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
     140             : 
     141        9704 :         if(fTools::equalZero(fVal))
     142             :         {
     143        2195 :             return ORIENTATION_NEUTRAL;
     144             :         }
     145             : 
     146        7509 :         if(fVal > 0.0)
     147             :         {
     148        6599 :             return ORIENTATION_POSITIVE;
     149             :         }
     150             :         else
     151             :         {
     152         910 :             return ORIENTATION_NEGATIVE;
     153             :         }
     154             :     }
     155             : 
     156       14971 :     B2DVector getPerpendicular( const B2DVector& rNormalizedVec )
     157             :     {
     158       14971 :         B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
     159       14971 :         return aPerpendicular;
     160             :     }
     161             : 
     162       33048 :     B2DVector getNormalizedPerpendicular( const B2DVector& rVec )
     163             :     {
     164       33048 :         B2DVector aPerpendicular(rVec);
     165       33048 :         aPerpendicular.normalize();
     166       33048 :         const double aTemp(-aPerpendicular.getY());
     167       33048 :         aPerpendicular.setY(aPerpendicular.getX());
     168       33048 :         aPerpendicular.setX(aTemp);
     169       33048 :         return aPerpendicular;
     170             :     }
     171             : 
     172      581712 :     B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec )
     173             :     {
     174      581712 :         B2DVector aRes( rVec );
     175      581712 :         return aRes*=rMat;
     176             :     }
     177             : 
     178      115521 :     B2VectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector )
     179             :     {
     180      115521 :         if(rBackVector.equalZero() || rForwardVector.equalZero())
     181             :         {
     182       26974 :             return CONTINUITY_NONE;
     183             :         }
     184             : 
     185       88547 :         if(fTools::equal(rBackVector.getX(), -rForwardVector.getX()) && fTools::equal(rBackVector.getY(), -rForwardVector.getY()))
     186             :         {
     187             :             // same direction and same length -> C2
     188       18738 :             return CONTINUITY_C2;
     189             :         }
     190             : 
     191       69809 :         if(areParallel(rBackVector, rForwardVector) && rBackVector.scalar(rForwardVector) < 0.0)
     192             :         {
     193             :             // parallel and opposite direction -> C1
     194       12195 :             return CONTINUITY_C1;
     195             :         }
     196             : 
     197       57614 :         return CONTINUITY_NONE;
     198             :     }
     199             : } // end of namespace basegfx
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10