bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / graphicfilter / idxf / dxfvec.hxx
blob3db285f7d628e3249cb04df4f3414f7facc62455
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _DXFVEC_HXX
21 #define _DXFVEC_HXX
23 #include <sal/types.h>
24 #include <vcl/lineinfo.hxx>
26 class Point;
28 class DXFLineInfo {
29 public:
30 LineStyle eStyle;
31 double fWidth;
32 sal_Int32 nDashCount;
33 double fDashLen;
34 sal_Int32 nDotCount;
35 double fDotLen;
36 double fDistance;
38 DXFLineInfo() :
39 eStyle(LINE_SOLID),
40 fWidth(0),
41 nDashCount(0),
42 fDashLen(0),
43 nDotCount(0),
44 fDotLen(0),
45 fDistance(0) {}
47 DXFLineInfo(const DXFLineInfo& x) :
48 eStyle(x.eStyle),
49 fWidth(x.fWidth),
50 nDashCount(x.nDashCount),
51 fDashLen(x.fDashLen),
52 nDotCount(x.nDotCount),
53 fDotLen(x.fDotLen),
54 fDistance(x.fDistance) {}
59 //------------------------------------------------------------------------------
60 //---------------------------- DXFVector ---------------------------------------
61 //------------------------------------------------------------------------------
62 // common 3D vector with doubles
64 class DXFVector {
66 public:
68 double fx,fy,fz; // public ! - why not?
70 inline DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0);
71 inline DXFVector(const DXFVector & rV);
73 // summation/subtraktion:
74 DXFVector & operator += (const DXFVector & rV);
75 DXFVector operator + (const DXFVector & rV) const;
76 DXFVector & operator -= (const DXFVector & rV);
77 DXFVector operator - (const DXFVector & rV) const;
79 // vector product
80 DXFVector operator * (const DXFVector & rV) const;
82 // skalar product:
83 double SProd(const DXFVector & rV) const;
85 // multiplication with scalar:
86 DXFVector & operator *= (double fs);
87 DXFVector operator * (double fs) const;
89 // length:
90 double Abs() const;
92 // vector with same direction and a length of 1:
93 DXFVector Unit() const;
95 // equivalence or net:
96 sal_Bool operator == (const DXFVector & rV) const;
97 sal_Bool operator != (const DXFVector & rV) const;
100 //------------------------------------------------------------------------------
101 //---------------------------- DXFTransform ------------------------------------
102 //------------------------------------------------------------------------------
103 // a transformation matrice specialized for our problem
105 class DXFTransform {
107 public:
109 DXFTransform();
110 // destination coordinate = source coordinate
112 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
113 const DXFVector & rShift);
114 // dest coordinate = translate(scale(source coordinate))
116 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
117 double fRotAngle,
118 const DXFVector & rShift);
119 // dest coordinate = translate(rotate(scale(source coordinate)))
120 // rotation around z-axis, fRotAngle in degrees.
122 DXFTransform(const DXFVector & rExtrusion);
123 // Transformation "ECS->WCS" via "Entity Extrusion Direction"
124 // ant the "Arbitrary Axis Algorithm"
125 // (See DXF-Docu from AutoDesk)
127 DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget);
128 // Transformation object space->picture space on the basis of direction
129 // destination point of a viewport
130 // (See DXF-Docu from AutoDesk: VPORT)
132 DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2);
133 // destination coordinate = rT2(rT1(source coordinate))
136 void Transform(const DXFVector & rSrc, DXFVector & rTgt) const;
137 // Transformation from DXFVector to DXFVector
139 void Transform(const DXFVector & rSrc, Point & rTgt) const;
140 // Transformation from DXFVector to SvPoint
142 void TransDir(const DXFVector & rSrc, DXFVector & rTgt) const;
143 // Transformation of a relative vector (so no translation)
145 sal_Bool TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const;
146 // Attemp to transform a circle (in xy plane) so that it results
147 // in an aligned ellipse. If the does not work because a ellipse of
148 // arbitrary position would be created, sal_False is returned.
149 // (The center point will not be transformed, use Transform(..))
151 sal_uLong TransLineWidth(double fW) const;
152 // Transforms the thickness of a line (as good as possible)
154 double CalcRotAngle() const;
155 // Calculates the rotation angle around z-axis (in degrees)
157 sal_Bool Mirror() const;
158 // Returns sal_True, if the matrice represents a left-handed coordinate system
160 LineInfo Transform(const DXFLineInfo& aDXFLineInfo) const;
161 // Transform to LineInfo
163 private:
164 DXFVector aMX;
165 DXFVector aMY;
166 DXFVector aMZ;
167 DXFVector aMP;
170 //------------------------------------------------------------------------------
171 //------------------------------- inlines --------------------------------------
172 //------------------------------------------------------------------------------
175 inline DXFVector::DXFVector(double fX, double fY, double fZ)
177 fx=fX; fy=fY; fz=fZ;
181 inline DXFVector::DXFVector(const DXFVector & rV)
183 fx=rV.fx; fy=rV.fy; fz=rV.fz;
187 inline DXFVector & DXFVector::operator += (const DXFVector & rV)
189 fx+=rV.fx; fy+=rV.fy; fz+=rV.fz;
190 return *this;
194 inline DXFVector DXFVector::operator + (const DXFVector & rV) const
196 return DXFVector(fx+rV.fx, fy+rV.fy, fz+rV.fz);
200 inline DXFVector & DXFVector::operator -= (const DXFVector & rV)
202 fx-=rV.fx; fy-=rV.fy; fz-=rV.fz;
203 return *this;
207 inline DXFVector DXFVector::operator - (const DXFVector & rV) const
209 return DXFVector(fx-rV.fx, fy-rV.fy, fz-rV.fz);
213 inline DXFVector DXFVector::operator * (const DXFVector & rV) const
215 return DXFVector(
216 fy * rV.fz - fz * rV.fy,
217 fz * rV.fx - fx * rV.fz,
218 fx * rV.fy - fy * rV.fx
223 inline double DXFVector::SProd(const DXFVector & rV) const
225 return fx*rV.fx + fy*rV.fy + fz*rV.fz;
229 inline DXFVector & DXFVector::operator *= (double fs)
231 fx*=fs; fy*=fs; fz*=fs;
232 return *this;
236 inline DXFVector DXFVector::operator * (double fs) const
238 return DXFVector(fx*fs,fy*fs,fz*fs);
242 inline sal_Bool DXFVector::operator == (const DXFVector & rV) const
244 if (fx==rV.fx && fy==rV.fy && fz==rV.fz) return sal_True;
245 else return sal_False;
249 inline sal_Bool DXFVector::operator != (const DXFVector & rV) const
251 if (fx!=rV.fx || fy!=rV.fy || fz!=rV.fz) return sal_True;
252 else return sal_False;
255 #endif
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */