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