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 .
22 #include <basegfx/tuple/b2dtuple.hxx>
23 #include <basegfx/vector/b2ivector.hxx>
24 #include <basegfx/vector/b2enums.hxx>
25 #include <basegfx/basegfxdllapi.h>
31 /** Base Point class with two double values
33 This class derives all operators and common handling for
34 a 2D data class from B2DTuple. All necessary extensions
35 which are special for 2D Vectors are added here.
39 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2DVector
: public ::basegfx::B2DTuple
42 /** Create a 2D Vector
44 The vector is initialized to (0.0, 0.0)
49 /** Create a 2D Vector
52 This parameter is used to initialize the X-coordinate
56 This parameter is used to initialize the Y-coordinate
59 B2DVector(double fX
, double fY
)
63 /** Create a copy of a 2D Vector
66 The 2D Vector which will be copied.
68 explicit B2DVector(const ::basegfx::B2IVector
& rVec
)
72 /** constructor with tuple to allow copy-constructing
73 from B2DTuple-based classes
75 B2DVector(Tuple2D
<double> const& rTuple
)
79 /** *=operator to allow usage from B2DVector, too
81 B2DVector
& operator*=( const B2DVector
& rPnt
)
88 /** *=operator to allow usage from B2DVector, too
90 B2DVector
& operator*=(double t
)
97 /** assignment operator to allow assigning the results
98 of B2DTuple calculations
100 B2DVector
& operator=(Tuple2D
<double> const& rVector
)
102 mnX
= rVector
.getX();
103 mnY
= rVector
.getY();
107 /** Calculate the length of this 2D Vector
109 @return The Length of the 2D Vector
111 double getLength() const;
113 /** Set the length of this 2D Vector
116 The to be achieved length of the 2D Vector
118 B2DVector
& setLength(double fLen
);
120 /** Normalize this 2D Vector
122 The length of the 2D Vector is set to 1.0
124 B2DVector
& normalize();
126 /** Calculate the Scalar with another 2D Vector
132 The Scalar value of the two involved 2D Vectors
134 double scalar( const B2DVector
& rVec
) const { return((mnX
* rVec
.mnX
) + (mnY
* rVec
.mnY
)); }
136 /** Calculate the length of the cross product with another 2D Vector
138 In 2D, returning an actual vector does not make much
139 sense here. The magnitude, although, can be readily
140 used for tasks such as angle calculations, since for
141 the returned value, the following equation holds:
142 retVal = getLength(this)*getLength(rVec)*sin(theta),
143 with theta being the angle between the two vectors.
149 The length of the cross product of the two involved 2D Vectors
151 double cross( const B2DVector
& rVec
) const { return(mnX
* rVec
.getY() - mnY
* rVec
.getX()); }
153 /** Calculate the Angle with another 2D Vector
159 The Angle value of the two involved 2D Vectors ranging from -pi to +pi
161 double angle( const B2DVector
& rVec
) const;
163 /** Transform vector by given transformation matrix.
165 Since this is a vector, translational components of the
166 matrix are disregarded.
168 B2DVector
& operator*=( const B2DHomMatrix
& rMat
);
170 static const B2DVector
& getEmptyVector();
173 // external operators
176 /** Calculate the orientation to another 2D Vector
185 The mathematical Orientation of the two involved 2D Vectors
187 BASEGFX_DLLPUBLIC B2VectorOrientation
getOrientation( const B2DVector
& rVecA
, const B2DVector
& rVecB
);
189 /** Calculate a perpendicular 2D Vector to the given one
194 @attention This only works if the given 2D Vector is normalized.
197 A 2D Vector perpendicular to the one given in parameter rVec
199 BASEGFX_DLLPUBLIC B2DVector
getPerpendicular( const B2DVector
& rNormalizedVec
);
201 /** Calculate a perpendicular 2D Vector to the given one,
202 normalize the given one as preparation
208 A normalized 2D Vector perpendicular to the one given in parameter rVec
210 BASEGFX_DLLPUBLIC B2DVector
getNormalizedPerpendicular( const B2DVector
& rVec
);
212 /** Test two vectors which need not to be normalized for parallelism
221 bool if the two values are parallel. Also true if
222 one of the vectors is empty.
224 BASEGFX_DLLPUBLIC
bool areParallel( const B2DVector
& rVecA
, const B2DVector
& rVecB
);
226 /** Transform vector by given transformation matrix.
228 Since this is a vector, translational components of the
229 matrix are disregarded.
231 BASEGFX_DLLPUBLIC B2DVector
operator*( const B2DHomMatrix
& rMat
, const B2DVector
& rVec
);
233 /** Test continuity between given vectors.
235 The two given vectors are assumed to describe control points on a
236 common point. Calculate if there is a continuity between them.
238 BASEGFX_DLLPUBLIC B2VectorContinuity
getContinuity( const B2DVector
& rBackVector
, const B2DVector
& rForwardVector
);
240 } // end of namespace basegfx
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */