LCOV - code coverage report
Current view: top level - libreoffice/basegfx/source/vector - b2dvector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 80 100.0 %
Date: 2012-12-17 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       15942 :     B2DVector& B2DVector::normalize()
      27             :     {
      28       15942 :         double fLen(scalar(*this));
      29             : 
      30       15942 :         if(fTools::equalZero(fLen))
      31             :         {
      32          12 :             mfX = 0.0;
      33          12 :             mfY = 0.0;
      34             :         }
      35             :         else
      36             :         {
      37       15930 :             const double fOne(1.0);
      38             : 
      39       15930 :             if(!fTools::equal(fOne, fLen))
      40             :             {
      41        9482 :                 fLen = sqrt(fLen);
      42             : 
      43        9482 :                 if(!fTools::equalZero(fLen))
      44             :                 {
      45        9482 :                     mfX /= fLen;
      46        9482 :                     mfY /= fLen;
      47             :                 }
      48             :             }
      49             :         }
      50             : 
      51       15942 :         return *this;
      52             :     }
      53             : 
      54         312 :     B2DVector& B2DVector::operator=( const B2DTuple& rVec )
      55             :     {
      56         312 :         mfX = rVec.getX();
      57         312 :         mfY = rVec.getY();
      58         312 :         return *this;
      59             :     }
      60             : 
      61             : 
      62        6612 :     double B2DVector::getLength() const
      63             :     {
      64        6612 :         if(fTools::equalZero(mfX))
      65             :         {
      66        4992 :             return fabs(mfY);
      67             :         }
      68        1620 :         else if(fTools::equalZero(mfY))
      69             :         {
      70        1438 :             return fabs(mfX);
      71             :         }
      72             : 
      73         182 :         return hypot( mfX, mfY );
      74             :     }
      75             : 
      76       18052 :     double B2DVector::scalar( const B2DVector& rVec ) const
      77             :     {
      78       18052 :         return((mfX * rVec.mfX) + (mfY * rVec.mfY));
      79             :     }
      80             : 
      81        5692 :     double B2DVector::cross( const B2DVector& rVec ) const
      82             :     {
      83        5692 :         return(mfX * rVec.getY() - mfY * rVec.getX());
      84             :     }
      85             : 
      86        1280 :     double B2DVector::angle( const B2DVector& rVec ) const
      87             :     {
      88        2560 :         return atan2(mfX * rVec.getY() - mfY * rVec.getX(),
      89        3840 :             mfX * rVec.getX() + mfY * rVec.getY());
      90             :     }
      91             : 
      92          10 :     const B2DVector& B2DVector::getEmptyVector()
      93             :     {
      94          10 :         return (const B2DVector&) B2DTuple::getEmptyTuple();
      95             :     }
      96             : 
      97       11740 :     B2DVector& B2DVector::operator*=( const B2DHomMatrix& rMat )
      98             :     {
      99       11740 :         const double fTempX( rMat.get(0,0)*mfX +
     100       11740 :                             rMat.get(0,1)*mfY );
     101       11740 :         const double fTempY( rMat.get(1,0)*mfX +
     102       11740 :                             rMat.get(1,1)*mfY );
     103       11740 :         mfX = fTempX;
     104       11740 :         mfY = fTempY;
     105             : 
     106       11740 :         return *this;
     107             :     }
     108             : 
     109         200 :     B2DVector& B2DVector::setLength(double fLen)
     110             :     {
     111         200 :         double fLenNow(scalar(*this));
     112             : 
     113         200 :         if(!fTools::equalZero(fLenNow))
     114             :         {
     115         194 :             const double fOne(10.0);
     116             : 
     117         194 :             if(!fTools::equal(fOne, fLenNow))
     118             :             {
     119         194 :                 fLen /= sqrt(fLenNow);
     120             :             }
     121             : 
     122         194 :             mfX *= fLen;
     123         194 :             mfY *= fLen;
     124             :         }
     125             : 
     126         200 :         return *this;
     127             :     }
     128             : 
     129       13758 :     bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB )
     130             :     {
     131       13758 :         const double fValA(rVecA.getX() * rVecB.getY());
     132       13758 :         const double fValB(rVecA.getY() * rVecB.getX());
     133             : 
     134       13758 :         return fTools::equal(fValA, fValB);
     135             :     }
     136             : 
     137        2840 :     B2VectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB )
     138             :     {
     139        2840 :         double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
     140             : 
     141        2840 :         if(fTools::equalZero(fVal))
     142             :         {
     143         344 :             return ORIENTATION_NEUTRAL;
     144             :         }
     145             : 
     146        2496 :         if(fVal > 0.0)
     147             :         {
     148        2168 :             return ORIENTATION_POSITIVE;
     149             :         }
     150             :         else
     151             :         {
     152         328 :             return ORIENTATION_NEGATIVE;
     153             :         }
     154             :     }
     155             : 
     156        1036 :     B2DVector getPerpendicular( const B2DVector& rNormalizedVec )
     157             :     {
     158        1036 :         B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
     159        1036 :         return aPerpendicular;
     160             :     }
     161             : 
     162        1776 :     B2DVector getNormalizedPerpendicular( const B2DVector& rVec )
     163             :     {
     164        1776 :         B2DVector aPerpendicular(rVec);
     165        1776 :         aPerpendicular.normalize();
     166        1776 :         const double aTemp(-aPerpendicular.getY());
     167        1776 :         aPerpendicular.setY(aPerpendicular.getX());
     168        1776 :         aPerpendicular.setX(aTemp);
     169        1776 :         return aPerpendicular;
     170             :     }
     171             : 
     172       11736 :     B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec )
     173             :     {
     174       11736 :         B2DVector aRes( rVec );
     175       11736 :         return aRes*=rMat;
     176             :     }
     177             : 
     178        5046 :     B2VectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector )
     179             :     {
     180        5046 :         if(rBackVector.equalZero() || rForwardVector.equalZero())
     181             :         {
     182        1022 :             return CONTINUITY_NONE;
     183             :         }
     184             : 
     185        4024 :         if(fTools::equal(rBackVector.getX(), -rForwardVector.getX()) && fTools::equal(rBackVector.getY(), -rForwardVector.getY()))
     186             :         {
     187             :             // same direction and same length -> C2
     188         134 :             return CONTINUITY_C2;
     189             :         }
     190             : 
     191        3890 :         if(areParallel(rBackVector, rForwardVector) && rBackVector.scalar(rForwardVector) < 0.0)
     192             :         {
     193             :             // parallel and opposite direction -> C1
     194        1828 :             return CONTINUITY_C1;
     195             :         }
     196             : 
     197        2062 :         return CONTINUITY_NONE;
     198             :     }
     199             : } // end of namespace basegfx
     200             : 
     201             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10