LCOV - code coverage report
Current view: top level - filter/source/graphicfilter/idxf - dxfvec.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 121 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 16 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             : 
      21             : #include <math.h>
      22             : #include <dxfvec.hxx>
      23             : #include <tools/gen.hxx>
      24             : 
      25             : 
      26             : //---------------------------- DXFVector ---------------------------------------
      27             : 
      28             : 
      29           0 : double DXFVector::Abs() const
      30             : {
      31           0 :     return sqrt(SProd(*this));
      32             : }
      33             : 
      34             : 
      35           0 : DXFVector DXFVector::Unit() const
      36             : {
      37             :     double flen;
      38             : 
      39           0 :     flen=Abs();
      40           0 :     if (flen!=0) return (*this)*(1.0/flen);
      41           0 :     else return DXFVector(1.0,0.0,0.0);
      42             : }
      43             : 
      44             : 
      45             : //---------------------------- DXFTransform ------------------------------------
      46             : 
      47             : 
      48           0 : DXFTransform::DXFTransform() :
      49             :     aMX(1.0, 0.0, 0.0),
      50             :     aMY(0.0, 1.0, 0.0),
      51             :     aMZ(0.0, 0.0, 1.0),
      52           0 :     aMP(0.0, 0.0, 0.0)
      53             : {
      54           0 : }
      55             : 
      56             : 
      57           0 : DXFTransform::DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
      58             :                            const DXFVector & rShift) :
      59             :     aMX(fScaleX, 0.0, 0.0),
      60             :     aMY(0.0, fScaleY, 0.0),
      61             :     aMZ(0.0, 0.0, fScaleZ),
      62           0 :     aMP(rShift)
      63             : {
      64           0 : }
      65             : 
      66             : 
      67           0 : DXFTransform::DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
      68             :                            double fRotAngle,
      69             :                            const DXFVector & rShift) :
      70             :     aMX(0.0, 0.0, 0.0),
      71             :     aMY(0.0, 0.0, 0.0),
      72             :     aMZ(0.0, 0.0, fScaleZ),
      73           0 :     aMP(rShift)
      74             : {
      75           0 :     aMX.fx=cos(3.14159265359/180.0*fRotAngle);
      76           0 :     aMX.fy=sin(3.14159265359/180.0*fRotAngle);
      77           0 :     aMY.fx=-aMX.fy;
      78           0 :     aMY.fy=aMX.fx;
      79           0 :     aMX*=fScaleX;
      80           0 :     aMY*=fScaleY;
      81           0 : }
      82             : 
      83             : 
      84           0 : DXFTransform::DXFTransform(const DXFVector & rExtrusion) :
      85           0 :     aMX(), aMY(), aMZ(), aMP(0.0, 0.0, 0.0)
      86             : {
      87             :     // 'Arbitrary Axis Algorithm' (cf. DXF documentation by Autodesk)
      88           0 :     if ( fabs(rExtrusion.fx) < 1.0/64.0 && fabs(rExtrusion.fy) < 1.0/64.0) {
      89           0 :         aMX = DXFVector(0.0, 1.0, 0.0) * rExtrusion;
      90             :     }
      91             :     else {
      92           0 :         aMX = DXFVector(0.0, 0.0, 1.0) * rExtrusion;
      93             :     }
      94           0 :     aMX=aMX.Unit();
      95           0 :     aMY=(rExtrusion*aMX).Unit();
      96           0 :     aMZ=rExtrusion.Unit();
      97           0 : }
      98             : 
      99             : 
     100           0 : DXFTransform::DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget) :
     101           0 :     aMX(), aMY(), aMZ(), aMP()
     102             : {
     103           0 :     DXFVector aV;
     104             : 
     105           0 :     aV=rViewDir.Unit();
     106           0 :     aMX.fz=aV.fx;
     107           0 :     aMY.fz=aV.fy;
     108           0 :     aMZ.fz=aV.fz;
     109             : 
     110           0 :     aMZ.fx=0;
     111           0 :     if (aV.fx==0) aMY.fx=0; else aMY.fx=sqrt(1/(1+aV.fy*aV.fy/(aV.fx*aV.fx)));
     112           0 :     aMX.fx=sqrt(1-aMY.fx*aMY.fx);
     113           0 :     if (aV.fx*aV.fy*aMY.fx>0) aMX.fx=-aMX.fx;
     114             : 
     115           0 :     aV=aV*DXFVector(aMX.fx,aMY.fx,aMZ.fx);
     116           0 :     aMX.fy=aV.fx;
     117           0 :     aMY.fy=aV.fy;
     118           0 :     aMZ.fy=aV.fz;
     119             : 
     120           0 :     if (aMZ.fy<0) {
     121           0 :         aMX.fy=-aMX.fy;
     122           0 :         aMY.fy=-aMY.fy;
     123           0 :         aMZ.fy=-aMZ.fy;
     124           0 :         aMX.fx=-aMX.fx;
     125           0 :         aMY.fx=-aMY.fx;
     126             :     }
     127             : 
     128           0 :     aV=DXFVector(0,0,0)-rViewTarget;
     129           0 :     aMP.fx = aV.fx * aMX.fx + aV.fy * aMY.fx + aV.fz * aMZ.fx;
     130           0 :     aMP.fy = aV.fx * aMX.fy + aV.fy * aMY.fy + aV.fz * aMZ.fy;
     131           0 :     aMP.fz = aV.fx * aMX.fz + aV.fy * aMY.fz + aV.fz * aMZ.fz;
     132           0 : }
     133             : 
     134             : 
     135           0 : DXFTransform::DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2) :
     136           0 :     aMX(),aMY(),aMZ(),aMP()
     137             : {
     138           0 :     rT2.TransDir(rT1.aMX,aMX);
     139           0 :     rT2.TransDir(rT1.aMY,aMY);
     140           0 :     rT2.TransDir(rT1.aMZ,aMZ);
     141           0 :     rT2.Transform(rT1.aMP,aMP);
     142           0 : }
     143             : 
     144             : 
     145           0 : void DXFTransform::Transform(const DXFVector & rSrc, DXFVector & rTgt) const
     146             : {
     147           0 :     rTgt.fx = rSrc.fx * aMX.fx + rSrc.fy * aMY.fx + rSrc.fz * aMZ.fx + aMP.fx;
     148           0 :     rTgt.fy = rSrc.fx * aMX.fy + rSrc.fy * aMY.fy + rSrc.fz * aMZ.fy + aMP.fy;
     149           0 :     rTgt.fz = rSrc.fx * aMX.fz + rSrc.fy * aMY.fz + rSrc.fz * aMZ.fz + aMP.fz;
     150           0 : }
     151             : 
     152             : 
     153           0 : void DXFTransform::Transform(const DXFVector & rSrc, Point & rTgt) const
     154             : {
     155           0 :     rTgt.X()=(long)( rSrc.fx * aMX.fx + rSrc.fy * aMY.fx + rSrc.fz * aMZ.fx + aMP.fx + 0.5 );
     156           0 :     rTgt.Y()=(long)( rSrc.fx * aMX.fy + rSrc.fy * aMY.fy + rSrc.fz * aMZ.fy + aMP.fy + 0.5 );
     157           0 : }
     158             : 
     159             : 
     160           0 : void DXFTransform::TransDir(const DXFVector & rSrc, DXFVector & rTgt) const
     161             : {
     162           0 :     rTgt.fx = rSrc.fx * aMX.fx + rSrc.fy * aMY.fx + rSrc.fz * aMZ.fx;
     163           0 :     rTgt.fy = rSrc.fx * aMX.fy + rSrc.fy * aMY.fy + rSrc.fz * aMZ.fy;
     164           0 :     rTgt.fz = rSrc.fx * aMX.fz + rSrc.fy * aMY.fz + rSrc.fz * aMZ.fz;
     165           0 : }
     166             : 
     167             : 
     168           0 : bool DXFTransform::TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const
     169             : {
     170           0 :     double fMXAbs=aMX.Abs();
     171           0 :     double fMYAbs=aMY.Abs();
     172           0 :     double fNearNull=(fMXAbs+fMYAbs)*0.001;
     173             : 
     174           0 :     if (fabs(aMX.fy)<=fNearNull && fabs(aMX.fz)<=fNearNull &&
     175           0 :         fabs(aMY.fx)<=fNearNull && fabs(aMY.fz)<=fNearNull)
     176             :     {
     177           0 :         rEx=fabs(aMX.fx*fRadius);
     178           0 :         rEy=fabs(aMY.fy*fRadius);
     179           0 :         return true;
     180             :     }
     181           0 :     else if (fabs(aMX.fx)<=fNearNull && fabs(aMX.fz)<=fNearNull &&
     182           0 :              fabs(aMY.fy)<=fNearNull && fabs(aMY.fz)<=fNearNull)
     183             :     {
     184           0 :         rEx=fabs(aMY.fx*fRadius);
     185           0 :         rEy=fabs(aMX.fy*fRadius);
     186           0 :         return true;
     187             :     }
     188           0 :     else if (fabs(fMXAbs-fMYAbs)<=fNearNull &&
     189           0 :              fabs(aMX.fz)<=fNearNull && fabs(aMY.fz)<=fNearNull)
     190             :     {
     191           0 :         rEx=rEy=fabs(((fMXAbs+fMYAbs)/2)*fRadius);
     192           0 :         return true;
     193             :     }
     194           0 :     else return false;
     195             : }
     196             : 
     197           0 : LineInfo DXFTransform::Transform(const DXFLineInfo& aDXFLineInfo) const
     198             : {
     199             :     double fex,fey,scale;
     200             : 
     201           0 :     fex=sqrt(aMX.fx*aMX.fx + aMX.fy*aMX.fy);
     202           0 :     fey=sqrt(aMY.fx*aMY.fx + aMY.fy*aMY.fy);
     203           0 :     scale = (fex+fey)/2.0;
     204             : 
     205           0 :     LineInfo aLineInfo;
     206             : 
     207           0 :     aLineInfo.SetStyle( aDXFLineInfo.eStyle );
     208           0 :     aLineInfo.SetWidth( (sal_Int32) (aDXFLineInfo.fWidth * scale + 0.5) );
     209           0 :     aLineInfo.SetDashCount( static_cast< sal_uInt16 >( aDXFLineInfo.nDashCount ) );
     210           0 :     aLineInfo.SetDashLen( (sal_Int32) (aDXFLineInfo.fDashLen * scale + 0.5) );
     211           0 :     aLineInfo.SetDotCount( static_cast< sal_uInt16 >( aDXFLineInfo.nDotCount ) );
     212           0 :     aLineInfo.SetDotLen( (sal_Int32) (aDXFLineInfo.fDotLen * scale + 0.5) );
     213           0 :     aLineInfo.SetDistance( (sal_Int32) (aDXFLineInfo.fDistance * scale + 0.5) );
     214             : 
     215           0 :     if ( aLineInfo.GetDashCount() > 0 && aLineInfo.GetDashLen() == 0 )
     216           0 :         aLineInfo.SetDashLen(1);
     217             : 
     218           0 :     if ( aLineInfo.GetDotCount() > 0 && aLineInfo.GetDotLen() == 0 )
     219           0 :         aLineInfo.SetDotLen(1);
     220             : 
     221           0 :     return aLineInfo;
     222             : }
     223             : 
     224           0 : sal_uInt32 DXFTransform::TransLineWidth(double fW) const
     225             : {
     226             :     double fex,fey;
     227             : 
     228           0 :     fex=sqrt(aMX.fx*aMX.fx + aMX.fy*aMX.fy);
     229           0 :     fey=sqrt(aMY.fx*aMY.fx + aMY.fy*aMY.fy);
     230             :     // ###
     231             :     // printf("fex=%f fey=%f\n", fex, fey);
     232           0 :     return (sal_uInt32)(fabs(fW)*(fex+fey)/2.0+0.5);
     233             : }
     234             : 
     235             : 
     236           0 : double DXFTransform::CalcRotAngle() const
     237             : {
     238           0 :     return atan2(aMX.fy,aMX.fx)/3.14159265359*180.0;
     239             : }
     240             : 
     241           0 : bool DXFTransform::Mirror() const
     242             : {
     243           0 :     if (aMZ.SProd(aMX*aMY)<0) return true; else return false;
     244             : }
     245             : 
     246             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11