workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / basegfx / vector / b2dvector.hxx
blobb698ccffe6091c27762ad36690f05193df48fec7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <basegfx/tuple/b2dtuple.hxx>
23 #include <basegfx/vector/b2ivector.hxx>
24 #include <basegfx/vector/b2enums.hxx>
25 #include <basegfx/basegfxdllapi.h>
27 namespace basegfx
29 class B2DHomMatrix;
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.
37 @see B2DTuple
39 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2DVector : public ::basegfx::B2DTuple
41 public:
42 /** Create a 2D Vector
44 The vector is initialized to (0.0, 0.0)
46 B2DVector()
49 /** Create a 2D Vector
51 @param fX
52 This parameter is used to initialize the X-coordinate
53 of the 2D Vector.
55 @param fY
56 This parameter is used to initialize the Y-coordinate
57 of the 2D Vector.
59 B2DVector(double fX, double fY)
60 : B2DTuple(fX, fY)
63 /** Create a copy of a 2D Vector
65 @param rVec
66 The 2D Vector which will be copied.
68 explicit B2DVector(const ::basegfx::B2IVector& rVec)
69 : B2DTuple(rVec)
72 /** constructor with tuple to allow copy-constructing
73 from B2DTuple-based classes
75 B2DVector(Tuple2D<double> const& rTuple)
76 : B2DTuple(rTuple)
79 /** *=operator to allow usage from B2DVector, too
81 B2DVector& operator*=( const B2DVector& rPnt )
83 mnX *= rPnt.mnX;
84 mnY *= rPnt.mnY;
85 return *this;
88 /** *=operator to allow usage from B2DVector, too
90 B2DVector& operator*=(double t)
92 mnX *= t;
93 mnY *= t;
94 return *this;
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();
104 return *this;
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
115 @param fLen
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
128 @param rVec
129 The second 2D Vector
131 @return
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.
145 @param rVec
146 The second 2D Vector
148 @return
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
155 @param rVec
156 The second 2D Vector
158 @return
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
178 @param rVecA
179 The first 2D Vector
181 @param rVecB
182 The second 2D Vector
184 @return
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
191 @param rVec
192 The source 2D Vector
194 @attention This only works if the given 2D Vector is normalized.
196 @return
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
204 @param rVec
205 The source 2D Vector
207 @return
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
214 @param rVecA
215 The first 2D Vector
217 @param rVecB
218 The second 2D Vector
220 @return
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: */