bump product version to 6.3.0.0.beta1
[LibreOffice.git] / include / basegfx / vector / b3dvector.hxx
blobe368f8849091b8638e56328b51b7b0bda0c931f1
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 #ifndef INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
21 #define INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
23 #include <basegfx/tuple/b3dtuple.hxx>
24 #include <basegfx/basegfxdllapi.h>
26 namespace basegfx
28 class B3DHomMatrix;
30 /** Base Point class with three double values
32 This class derives all operators and common handling for
33 a 3D data class from B3DTuple. All necessary extensions
34 which are special for 3D Vectors are added here.
36 @see B3DTuple
38 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DVector : public ::basegfx::B3DTuple
40 public:
41 /** Create a 3D Vector
43 The vector is initialized to (0.0, 0.0, 0.0)
45 B3DVector()
46 : B3DTuple()
49 /** Create a 3D Vector
51 @param fX
52 This parameter is used to initialize the X-coordinate
53 of the 3D Vector.
55 @param fY
56 This parameter is used to initialize the Y-coordinate
57 of the 3D Vector.
59 @param fZ
60 This parameter is used to initialize the Z-coordinate
61 of the 3D Vector.
63 B3DVector(double fX, double fY, double fZ)
64 : B3DTuple(fX, fY, fZ)
67 /** constructor with tuple to allow copy-constructing
68 from B3DTuple-based classes
70 B3DVector(const ::basegfx::B3DTuple& rTuple)
71 : B3DTuple(rTuple)
74 /** *=operator to allow usage from B3DVector, too
76 B3DVector& operator*=( const B3DVector& rPnt )
78 mfX *= rPnt.mfX;
79 mfY *= rPnt.mfY;
80 mfZ *= rPnt.mfZ;
81 return *this;
84 /** *=operator to allow usage from B3DVector, too
86 B3DVector& operator*=(double t)
88 mfX *= t;
89 mfY *= t;
90 mfZ *= t;
91 return *this;
94 /** assignment operator to allow assigning the results
95 of B3DTuple calculations
97 B3DVector& operator=( const ::basegfx::B3DTuple& rVec )
99 mfX = rVec.getX();
100 mfY = rVec.getY();
101 mfZ = rVec.getZ();
102 return *this;
105 /** Calculate the length of this 3D Vector
107 @return The Length of the 3D Vector
109 double getLength() const
111 double fLen(scalar(*this));
112 if((0.0 == fLen) || (1.0 == fLen))
113 return fLen;
114 return sqrt(fLen);
117 /** Calculate the length in the XZ-Plane for this 3D Vector
119 @return The XZ-Plane Length of the 3D Vector
121 double getXZLength() const
123 double fLen((mfX * mfX) + (mfZ * mfZ)); // #i73040#
124 if((0.0 == fLen) || (1.0 == fLen))
125 return fLen;
126 return sqrt(fLen);
129 /** Calculate the length in the YZ-Plane for this 3D Vector
131 @return The YZ-Plane Length of the 3D Vector
133 double getYZLength() const
135 double fLen((mfY * mfY) + (mfZ * mfZ));
136 if((0.0 == fLen) || (1.0 == fLen))
137 return fLen;
138 return sqrt(fLen);
141 /** Set the length of this 3D Vector
143 @param fLen
144 The to be achieved length of the 3D Vector
146 B3DVector& setLength(double fLen)
148 double fLenNow(scalar(*this));
150 if(!::basegfx::fTools::equalZero(fLenNow))
152 const double fOne(1.0);
154 if(!::basegfx::fTools::equal(fOne, fLenNow))
156 fLen /= sqrt(fLenNow);
159 mfX *= fLen;
160 mfY *= fLen;
161 mfZ *= fLen;
164 return *this;
167 /** Normalize this 3D Vector
169 The length of the 3D Vector is set to 1.0
171 B3DVector& normalize();
173 /** get a 3D Vector which is perpendicular to this and a given 3D Vector
175 @attention This only works if this and the given 3D Vector are
176 both normalized.
178 @param rNormalizedVec
179 A normalized 3D Vector.
181 @return
182 A 3D Vector perpendicular to this and the given one
184 B3DVector getPerpendicular(const B3DVector& rNormalizedVec) const;
186 /** Calculate the Scalar product
188 This method calculates the Scalar product between this
189 and the given 3D Vector.
191 @param rVec
192 A second 3D Vector.
194 @return
195 The Scalar Product of two 3D Vectors
197 double scalar(const B3DVector& rVec) const
199 return ((mfX * rVec.mfX) + (mfY * rVec.mfY) + (mfZ * rVec.mfZ));
202 /** Transform vector by given transformation matrix.
204 Since this is a vector, translational components of the
205 matrix are disregarded.
207 B3DVector& operator*=( const B3DHomMatrix& rMat );
209 static const B3DVector& getEmptyVector()
211 return static_cast<const B3DVector&>( ::basegfx::B3DTuple::getEmptyTuple() );
215 // external operators
218 /** Test two vectors which need not to be normalized for parallelism
220 @param rVecA
221 The first 3D Vector
223 @param rVecB
224 The second 3D Vector
226 @return
227 bool if the two values are parallel. Also true if
228 one of the vectors is empty.
230 BASEGFX_DLLPUBLIC bool areParallel( const B3DVector& rVecA, const B3DVector& rVecB );
232 /** Transform vector by given transformation matrix.
234 Since this is a vector, translational components of the
235 matrix are disregarded.
237 BASEGFX_DLLPUBLIC B3DVector operator*( const B3DHomMatrix& rMat, const B3DVector& rVec );
239 /** Calculate the Cross Product of two 3D Vectors
241 @param rVecA
242 A first 3D Vector.
244 @param rVecB
245 A second 3D Vector.
247 @return
248 The Cross Product of both 3D Vectors
250 inline B3DVector cross(const B3DVector& rVecA, const B3DVector& rVecB)
252 B3DVector aVec(
253 rVecA.getY() * rVecB.getZ() - rVecA.getZ() * rVecB.getY(),
254 rVecA.getZ() * rVecB.getX() - rVecA.getX() * rVecB.getZ(),
255 rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
256 return aVec;
258 } // end of namespace basegfx
260 #endif // INCLUDED_BASEGFX_VECTOR_B3DVECTOR_HXX
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */