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 : #ifndef INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
21 : #define INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
22 :
23 : #include <basegfx/tuple/b2dtuple.hxx>
24 : #include <basegfx/vector/b2ivector.hxx>
25 : #include <basegfx/vector/b2enums.hxx>
26 : #include <basegfx/basegfxdllapi.h>
27 :
28 : namespace basegfx
29 : {
30 : // predeclaration
31 : class B2DHomMatrix;
32 :
33 : /** Base Point class with two double values
34 :
35 : This class derives all operators and common handling for
36 : a 2D data class from B2DTuple. All necessary extensions
37 : which are special for 2D Vectors are added here.
38 :
39 : @see B2DTuple
40 : */
41 0 : class BASEGFX_DLLPUBLIC B2DVector : public ::basegfx::B2DTuple
42 : {
43 : public:
44 : /** Create a 2D Vector
45 :
46 : The vector is initialized to (0.0, 0.0)
47 : */
48 0 : B2DVector()
49 0 : : B2DTuple()
50 0 : {}
51 :
52 : /** Create a 2D Vector
53 :
54 : @param fX
55 : This parameter is used to initialize the X-coordinate
56 : of the 2D Vector.
57 :
58 : @param fY
59 : This parameter is used to initialize the Y-coordinate
60 : of the 2D Vector.
61 : */
62 0 : B2DVector(double fX, double fY)
63 0 : : B2DTuple(fX, fY)
64 0 : {}
65 :
66 : /** Create a copy of a 2D Vector
67 :
68 : @param rVec
69 : The 2D Vector which will be copied.
70 : */
71 0 : B2DVector(const B2DVector& rVec)
72 0 : : B2DTuple(rVec)
73 0 : {}
74 :
75 : /** Create a copy of a 2D Vector
76 :
77 : @param rVec
78 : The 2D Vector which will be copied.
79 : */
80 0 : explicit B2DVector(const ::basegfx::B2IVector& rVec)
81 0 : : B2DTuple(rVec)
82 0 : {}
83 :
84 : /** constructor with tuple to allow copy-constructing
85 : from B2DTuple-based classes
86 : */
87 0 : B2DVector(const ::basegfx::B2DTuple& rTuple)
88 0 : : B2DTuple(rTuple)
89 0 : {}
90 :
91 0 : ~B2DVector()
92 0 : {}
93 :
94 : /** *=operator to allow usage from B2DVector, too
95 : */
96 0 : B2DVector& operator*=( const B2DVector& rPnt )
97 : {
98 0 : mfX *= rPnt.mfX;
99 0 : mfY *= rPnt.mfY;
100 0 : return *this;
101 : }
102 :
103 : /** *=operator to allow usage from B2DVector, too
104 : */
105 0 : B2DVector& operator*=(double t)
106 : {
107 0 : mfX *= t;
108 0 : mfY *= t;
109 0 : return *this;
110 : }
111 :
112 : /** assignment operator to allow assigning the results
113 : of B2DTuple calculations
114 : */
115 : B2DVector& operator=( const ::basegfx::B2DTuple& rVec );
116 :
117 : /** Calculate the length of this 2D Vector
118 :
119 : @return The Length of the 2D Vector
120 : */
121 : double getLength() const;
122 :
123 : /** Set the length of this 2D Vector
124 :
125 : @param fLen
126 : The to be achieved length of the 2D Vector
127 : */
128 : B2DVector& setLength(double fLen);
129 :
130 : /** Normalize this 2D Vector
131 :
132 : The length of the 2D Vector is set to 1.0
133 : */
134 : B2DVector& normalize();
135 :
136 : /** Calculate the Scalar with another 2D Vector
137 :
138 : @param rVec
139 : The second 2D Vector
140 :
141 : @return
142 : The Scalar value of the two involved 2D Vectors
143 : */
144 : double scalar( const B2DVector& rVec ) const;
145 :
146 : /** Calculate the length of the cross product with another 2D Vector
147 :
148 : In 2D, returning an actual vector does not make much
149 : sense here. The magnitude, although, can be readily
150 : used for tasks such as angle calculations, since for
151 : the returned value, the following equation holds:
152 : retVal = getLength(this)*getLength(rVec)*sin(theta),
153 : with theta being the angle between the two vectors.
154 :
155 : @param rVec
156 : The second 2D Vector
157 :
158 : @return
159 : The length of the cross product of the two involved 2D Vectors
160 : */
161 : double cross( const B2DVector& rVec ) const;
162 :
163 : /** Calculate the Angle with another 2D Vector
164 :
165 : @param rVec
166 : The second 2D Vector
167 :
168 : @return
169 : The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2
170 : */
171 : double angle( const B2DVector& rVec ) const;
172 :
173 : /** Transform vector by given transformation matrix.
174 :
175 : Since this is a vector, translational components of the
176 : matrix are disregarded.
177 : */
178 : B2DVector& operator*=( const B2DHomMatrix& rMat );
179 :
180 : static const B2DVector& getEmptyVector();
181 : };
182 :
183 : // external operators
184 :
185 :
186 : /** Calculate the orientation to another 2D Vector
187 :
188 : @param rVecA
189 : The first 2D Vector
190 :
191 : @param rVecB
192 : The second 2D Vector
193 :
194 : @return
195 : The mathematical Orientation of the two involved 2D Vectors
196 : */
197 : BASEGFX_DLLPUBLIC B2VectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB );
198 :
199 : /** Calculate a perpendicular 2D Vector to the given one
200 :
201 : @param rVec
202 : The source 2D Vector
203 :
204 : @attention This only works if the given 2D Vector is normalized.
205 :
206 : @return
207 : A 2D Vector perpendicular to the one given in parameter rVec
208 : */
209 : BASEGFX_DLLPUBLIC B2DVector getPerpendicular( const B2DVector& rNormalizedVec );
210 :
211 : /** Calculate a perpendicular 2D Vector to the given one,
212 : normalize the given one as preparation
213 :
214 : @param rVec
215 : The source 2D Vector
216 :
217 : @return
218 : A normalized 2D Vector perpendicular to the one given in parameter rVec
219 : */
220 : BASEGFX_DLLPUBLIC B2DVector getNormalizedPerpendicular( const B2DVector& rVec );
221 :
222 : /** Test two vectors which need not to be normalized for parallelism
223 :
224 : @param rVecA
225 : The first 2D Vector
226 :
227 : @param rVecB
228 : The second 2D Vector
229 :
230 : @return
231 : bool if the two values are parallel. Also true if
232 : one of the vectors is empty.
233 : */
234 : BASEGFX_DLLPUBLIC bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB );
235 :
236 : /** Transform vector by given transformation matrix.
237 :
238 : Since this is a vector, translational components of the
239 : matrix are disregarded.
240 : */
241 : BASEGFX_DLLPUBLIC B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec );
242 :
243 : /** Test continuity between given vectors.
244 :
245 : The two given vectors are assumed to describe control points on a
246 : common point. Calculate if there is a continuity between them.
247 : */
248 : BASEGFX_DLLPUBLIC B2VectorContinuity getContinuity( const B2DVector& rBackVector, const B2DVector& rForwardVector );
249 :
250 : } // end of namespace basegfx
251 :
252 : #endif // INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|