LibreOffice Module vcl (master) 1
dxfvec.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/types.h>
23#include <vcl/lineinfo.hxx>
24
25class Point;
26
28public:
30 sal_Int32 nDashCount;
31 double fDashLen;
32 sal_Int32 nDotCount;
33 double fDotLen;
34 double fDistance;
35
38 nDashCount(0),
39 fDashLen(0),
40 nDotCount(0),
41 fDotLen(0),
42 fDistance(0) {}
43};
44
45
46//---------------------------- DXFVector ---------------------------------------
47
48// common 3D vector with doubles
49
50class DXFVector {
51
52public:
53
54 double fx,fy,fz; // public ! - why not?
55
56 inline DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0);
57
58 // summation/subtraktion:
59 DXFVector & operator += (const DXFVector & rV);
60 DXFVector operator + (const DXFVector & rV) const;
61 DXFVector operator - (const DXFVector & rV) const;
62
63 // vector product
64 DXFVector operator * (const DXFVector & rV) const;
65
66 // scalar product:
67 double SProd(const DXFVector & rV) const;
68
69 // multiplication with scalar:
70 DXFVector & operator *= (double fs);
71 DXFVector operator * (double fs) const;
72
73 // length:
74 double Abs() const;
75
76 // vector with same direction and a length of 1:
77 DXFVector Unit() const;
78
79 // equivalence or net:
80 bool operator == (const DXFVector & rV) const;
81};
82
83
84//---------------------------- DXFTransform ------------------------------------
85
86// a transformation matrice specialized for our problem
87
89
90public:
91
93 // destination coordinate = source coordinate
94
95 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
96 const DXFVector & rShift);
97 // dest coordinate = translate(scale(source coordinate))
98
99 DXFTransform(double fScaleX, double fScaleY, double fScaleZ,
100 double fRotAngle,
101 const DXFVector & rShift);
102 // dest coordinate = translate(rotate(scale(source coordinate)))
103 // rotation around z-axis, fRotAngle in degrees.
104
105 DXFTransform(const DXFVector & rExtrusion);
106 // Transformation "ECS->WCS" via "Entity Extrusion Direction"
107 // ant the "Arbitrary Axis Algorithm"
108 // (See DXF-Docu from AutoDesk)
109
110 DXFTransform(const DXFVector & rViewDir, const DXFVector & rViewTarget);
111 // Transformation object space->picture space on the basis of direction
112 // destination point of a viewport
113 // (See DXF-Docu from AutoDesk: VPORT)
114
115 DXFTransform(const DXFTransform & rT1, const DXFTransform & rT2);
116 // destination coordinate = rT2(rT1(source coordinate))
117
118
119 void Transform(const DXFVector & rSrc, DXFVector & rTgt) const;
120 // Transformation from DXFVector to DXFVector
121
122 void Transform(const DXFVector & rSrc, Point & rTgt) const;
123 // Transformation from DXFVector to SvPoint
124
125 void TransDir(const DXFVector & rSrc, DXFVector & rTgt) const;
126 // Transformation of a relative vector (so no translation)
127
128 bool TransCircleToEllipse(double fRadius, double & rEx, double & rEy) const;
129 // Attempt to transform a circle (in xy plane) so that it results
130 // in an aligned ellipse. If the does not work because an ellipse of
131 // arbitrary position would be created, sal_False is returned.
132 // (The center point will not be transformed, use Transform(..))
133
134 double CalcRotAngle() const;
135 // Calculates the rotation angle around z-axis (in degrees)
136
137 bool Mirror() const;
138 // Returns sal_True, if the matrice represents a left-handed coordinate system
139
140 LineInfo Transform(const DXFLineInfo& aDXFLineInfo) const;
141 // Transform to LineInfo
142
143private:
148};
149
150
151//------------------------------- inlines --------------------------------------
152
153
154inline DXFVector::DXFVector(double fX, double fY, double fZ)
155{
156 fx=fX; fy=fY; fz=fZ;
157}
158
159
161{
162 fx+=rV.fx; fy+=rV.fy; fz+=rV.fz;
163 return *this;
164}
165
166
168{
169 return DXFVector(fx+rV.fx, fy+rV.fy, fz+rV.fz);
170}
171
172
174{
175 return DXFVector(fx-rV.fx, fy-rV.fy, fz-rV.fz);
176}
177
178
180{
181 return DXFVector(
182 fy * rV.fz - fz * rV.fy,
183 fz * rV.fx - fx * rV.fz,
184 fx * rV.fy - fy * rV.fx
185 );
186}
187
188
189inline double DXFVector::SProd(const DXFVector & rV) const
190{
191 return fx*rV.fx + fy*rV.fy + fz*rV.fz;
192}
193
194
196{
197 fx*=fs; fy*=fs; fz*=fs;
198 return *this;
199}
200
201
203{
204 return DXFVector(fx*fs,fy*fs,fz*fs);
205}
206
207
208inline bool DXFVector::operator == (const DXFVector & rV) const
209{
210 if (fx==rV.fx && fy==rV.fy && fz==rV.fz) return true;
211 else return false;
212}
213
214/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nDashCount
Definition: dxfvec.hxx:30
double fDashLen
Definition: dxfvec.hxx:31
LineStyle eStyle
Definition: dxfvec.hxx:29
sal_Int32 nDotCount
Definition: dxfvec.hxx:32
double fDistance
Definition: dxfvec.hxx:34
DXFLineInfo()
Definition: dxfvec.hxx:36
double fDotLen
Definition: dxfvec.hxx:33
DXFVector aMX
Definition: dxfvec.hxx:144
void TransDir(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:158
DXFVector aMY
Definition: dxfvec.hxx:145
DXFVector aMZ
Definition: dxfvec.hxx:146
DXFVector aMP
Definition: dxfvec.hxx:147
void Transform(const DXFVector &rSrc, DXFVector &rTgt) const
Definition: dxfvec.cxx:143
DXFTransform()
Definition: dxfvec.cxx:48
bool Mirror() const
Definition: dxfvec.cxx:227
double CalcRotAngle() const
Definition: dxfvec.cxx:222
bool TransCircleToEllipse(double fRadius, double &rEx, double &rEy) const
Definition: dxfvec.cxx:166
DXFVector operator*(const DXFVector &rV) const
Definition: dxfvec.hxx:179
DXFVector operator-(const DXFVector &rV) const
Definition: dxfvec.hxx:173
DXFVector & operator+=(const DXFVector &rV)
Definition: dxfvec.hxx:160
DXFVector Unit() const
Definition: dxfvec.cxx:35
double fx
Definition: dxfvec.hxx:54
double SProd(const DXFVector &rV) const
Definition: dxfvec.hxx:189
bool operator==(const DXFVector &rV) const
Definition: dxfvec.hxx:208
DXFVector & operator*=(double fs)
Definition: dxfvec.hxx:195
double Abs() const
Definition: dxfvec.cxx:29
DXFVector operator+(const DXFVector &rV) const
Definition: dxfvec.hxx:167
double fz
Definition: dxfvec.hxx:54
double fy
Definition: dxfvec.hxx:54
DXFVector(double fX=0.0, double fY=0.0, double fZ=0.0)
Definition: dxfvec.hxx:154
LineStyle
Definition: vclenum.hxx:165