LCOV - code coverage report
Current view: top level - libreoffice/basegfx/source/vector - b3dvector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 33 48.5 %
Date: 2012-12-27 Functions: 2 5 40.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/b3dvector.hxx>
      21             : #include <basegfx/matrix/b3dhommatrix.hxx>
      22             : 
      23             : //////////////////////////////////////////////////////////////////////////////
      24             : 
      25             : namespace basegfx
      26             : {
      27         164 :     B3DVector& B3DVector::normalize()
      28             :     {
      29         164 :         double fLen(scalar(*this));
      30             : 
      31         164 :         if(!::basegfx::fTools::equalZero(fLen))
      32             :         {
      33         164 :             const double fOne(1.0);
      34             : 
      35         164 :             if(!::basegfx::fTools::equal(fOne, fLen))
      36             :             {
      37          82 :                 fLen = sqrt(fLen);
      38             : 
      39          82 :                 if(!::basegfx::fTools::equalZero(fLen))
      40             :                 {
      41          82 :                     mfX /= fLen;
      42          82 :                     mfY /= fLen;
      43          82 :                     mfZ /= fLen;
      44             :                 }
      45             :             }
      46             :         }
      47             : 
      48         164 :         return *this;
      49             :     }
      50             : 
      51          41 :     B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const
      52             :     {
      53          41 :         B3DVector aNew(*this);
      54          41 :         aNew = cross(aNew, rNormalizedVec);
      55          41 :         aNew.normalize();
      56          41 :         return aNew;
      57             :     }
      58             : 
      59           0 :     B3DVector& B3DVector::operator*=( const ::basegfx::B3DHomMatrix& rMat )
      60             :     {
      61           0 :         const double fTempX( rMat.get(0,0)*mfX + rMat.get(0,1)*mfY + rMat.get(0,2)*mfZ );
      62           0 :         const double fTempY( rMat.get(1,0)*mfX + rMat.get(1,1)*mfY + rMat.get(1,2)*mfZ );
      63           0 :         const double fTempZ( rMat.get(2,0)*mfX + rMat.get(2,1)*mfY + rMat.get(2,2)*mfZ );
      64           0 :         mfX = fTempX;
      65           0 :         mfY = fTempY;
      66           0 :         mfZ = fTempZ;
      67             : 
      68           0 :         return *this;
      69             :     }
      70             : 
      71           0 :     B3DVector operator*( const ::basegfx::B3DHomMatrix& rMat, const B3DVector& rVec )
      72             :     {
      73           0 :         B3DVector aRes( rVec );
      74           0 :         return aRes*=rMat;
      75             :     }
      76             : 
      77           0 :     bool areParallel( const B3DVector& rVecA, const B3DVector& rVecB )
      78             :     {
      79             :         // i think fastest is to compare relations, need no square or division
      80           0 :         if(!fTools::equal(rVecA.getX() * rVecB.getY(), rVecA.getY() * rVecB.getX()))
      81           0 :             return false;
      82             : 
      83           0 :         if(!fTools::equal(rVecA.getX() * rVecB.getZ(), rVecA.getZ() * rVecB.getX()))
      84           0 :             return false;
      85             : 
      86           0 :         return (fTools::equal(rVecA.getY() * rVecB.getZ(), rVecA.getZ() * rVecB.getY()));
      87             :     }
      88             : 
      89             : } // end of namespace basegfx
      90             : 
      91             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10