1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
21 #define INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
23 #include <basegfx/tuple/b2dtuple.hxx>
24 #include <basegfx/vector/b2ivector.hxx>
25 #include <basegfx/vector/b2enums.hxx>
26 #include <basegfx/basegfxdllapi.h>
32 /** Base Point class with two double values
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.
40 class BASEGFX_DLLPUBLIC B2DVector
: public ::basegfx::B2DTuple
43 /** Create a 2D Vector
45 The vector is initialized to (0.0, 0.0)
51 /** Create a 2D Vector
54 This parameter is used to initialize the X-coordinate
58 This parameter is used to initialize the Y-coordinate
61 B2DVector(double fX
, double fY
)
65 /** Create a copy of a 2D Vector
68 The 2D Vector which will be copied.
70 explicit B2DVector(const ::basegfx::B2IVector
& rVec
)
74 /** constructor with tuple to allow copy-constructing
75 from B2DTuple-based classes
77 B2DVector(const ::basegfx::B2DTuple
& rTuple
)
81 /** *=operator to allow usage from B2DVector, too
83 B2DVector
& operator*=( const B2DVector
& rPnt
)
90 /** *=operator to allow usage from B2DVector, too
92 B2DVector
& operator*=(double t
)
99 /** assignment operator to allow assigning the results
100 of B2DTuple calculations
102 B2DVector
& operator=( const ::basegfx::B2DTuple
& rVec
);
104 /** Calculate the length of this 2D Vector
106 @return The Length of the 2D Vector
108 double getLength() const;
110 /** Set the length of this 2D Vector
113 The to be achieved length of the 2D Vector
115 B2DVector
& setLength(double fLen
);
117 /** Normalize this 2D Vector
119 The length of the 2D Vector is set to 1.0
121 B2DVector
& normalize();
123 /** Calculate the Scalar with another 2D Vector
129 The Scalar value of the two involved 2D Vectors
131 double scalar( const B2DVector
& rVec
) const { return((mfX
* rVec
.mfX
) + (mfY
* rVec
.mfY
)); }
133 /** Calculate the length of the cross product with another 2D Vector
135 In 2D, returning an actual vector does not make much
136 sense here. The magnitude, although, can be readily
137 used for tasks such as angle calculations, since for
138 the returned value, the following equation holds:
139 retVal = getLength(this)*getLength(rVec)*sin(theta),
140 with theta being the angle between the two vectors.
146 The length of the cross product of the two involved 2D Vectors
148 double cross( const B2DVector
& rVec
) const { return(mfX
* rVec
.getY() - mfY
* rVec
.getX()); }
150 /** Calculate the Angle with another 2D Vector
156 The Angle value of the two involved 2D Vectors in -pi/2 < return < pi/2
158 double angle( const B2DVector
& rVec
) const;
160 /** Transform vector by given transformation matrix.
162 Since this is a vector, translational components of the
163 matrix are disregarded.
165 B2DVector
& operator*=( const B2DHomMatrix
& rMat
);
167 static const B2DVector
& getEmptyVector();
170 // external operators
173 /** Calculate the orientation to another 2D Vector
182 The mathematical Orientation of the two involved 2D Vectors
184 BASEGFX_DLLPUBLIC B2VectorOrientation
getOrientation( const B2DVector
& rVecA
, const B2DVector
& rVecB
);
186 /** Calculate a perpendicular 2D Vector to the given one
191 @attention This only works if the given 2D Vector is normalized.
194 A 2D Vector perpendicular to the one given in parameter rVec
196 BASEGFX_DLLPUBLIC B2DVector
getPerpendicular( const B2DVector
& rNormalizedVec
);
198 /** Calculate a perpendicular 2D Vector to the given one,
199 normalize the given one as preparation
205 A normalized 2D Vector perpendicular to the one given in parameter rVec
207 BASEGFX_DLLPUBLIC B2DVector
getNormalizedPerpendicular( const B2DVector
& rVec
);
209 /** Test two vectors which need not to be normalized for parallelism
218 bool if the two values are parallel. Also true if
219 one of the vectors is empty.
221 BASEGFX_DLLPUBLIC
bool areParallel( const B2DVector
& rVecA
, const B2DVector
& rVecB
);
223 /** Transform vector by given transformation matrix.
225 Since this is a vector, translational components of the
226 matrix are disregarded.
228 BASEGFX_DLLPUBLIC B2DVector
operator*( const B2DHomMatrix
& rMat
, const B2DVector
& rVec
);
230 /** Test continuity between given vectors.
232 The two given vectors are assumed to describe control points on a
233 common point. Calculate if there is a continuity between them.
235 BASEGFX_DLLPUBLIC B2VectorContinuity
getContinuity( const B2DVector
& rBackVector
, const B2DVector
& rForwardVector
);
237 } // end of namespace basegfx
239 #endif // INCLUDED_BASEGFX_VECTOR_B2DVECTOR_HXX
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */