bump product version to 4.1.6.2
[LibreOffice.git] / include / basegfx / vector / b3ivector.hxx
blob8248ade15cb0a8f05b67a2a2a92908b5db1f9ae4
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 _BGFX_VECTOR_B3IVECTOR_HXX
21 #define _BGFX_VECTOR_B3IVECTOR_HXX
23 #include <basegfx/tuple/b3ituple.hxx>
24 #include <basegfx/basegfxdllapi.h>
26 namespace basegfx
28 // predeclaration
29 class B3DHomMatrix;
31 /** Base Point class with three sal_Int32 values
33 This class derives all operators and common handling for
34 a 3D data class from B3ITuple. All necessary extensions
35 which are special for 3D Vectors are added here.
37 @see B3ITuple
39 class BASEGFX_DLLPUBLIC B3IVector : public ::basegfx::B3ITuple
41 public:
42 /** Create a 3D Vector
44 The vector is initialized to (0, 0, 0)
46 B3IVector()
47 : B3ITuple()
50 /** Create a 3D Vector
52 @param nX
53 This parameter is used to initialize the X-coordinate
54 of the 3D Vector.
56 @param nY
57 This parameter is used to initialize the Y-coordinate
58 of the 3D Vector.
60 @param nZ
61 This parameter is used to initialize the Z-coordinate
62 of the 3D Vector.
64 B3IVector(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ)
65 : B3ITuple(nX, nY, nZ)
68 /** Create a copy of a 3D Vector
70 @param rVec
71 The 3D Vector which will be copied.
73 B3IVector(const B3IVector& rVec)
74 : B3ITuple(rVec)
77 /** constructor with tuple to allow copy-constructing
78 from B3ITuple-based classes
80 B3IVector(const ::basegfx::B3ITuple& rTuple)
81 : B3ITuple(rTuple)
84 ~B3IVector()
87 /** *=operator to allow usage from B3IVector, too
89 B3IVector& operator*=( const B3IVector& rPnt )
91 mnX *= rPnt.mnX;
92 mnY *= rPnt.mnY;
93 mnZ *= rPnt.mnZ;
94 return *this;
97 /** *=operator to allow usage from B3IVector, too
99 B3IVector& operator*=(sal_Int32 t)
101 mnX *= t;
102 mnY *= t;
103 mnZ *= t;
104 return *this;
107 /** assignment operator to allow assigning the results
108 of B3ITuple calculations
110 B3IVector& operator=( const ::basegfx::B3ITuple& rVec )
112 mnX = rVec.getX();
113 mnY = rVec.getY();
114 mnZ = rVec.getZ();
115 return *this;
118 /** Calculate the length of this 3D Vector
120 @return The Length of the 3D Vector
122 double getLength(void) const
124 double fLen(scalar(*this));
125 if((0 == fLen) || (1.0 == fLen))
126 return fLen;
127 return sqrt(fLen);
130 /** Calculate the length in the XY-Plane for this 3D Vector
132 @return The XY-Plane Length of the 3D Vector
134 double getXYLength(void) const
136 double fLen((mnX * mnX) + (mnY * mnY));
137 if((0 == fLen) || (1.0 == fLen))
138 return fLen;
139 return sqrt(fLen);
142 /** Calculate the length in the XZ-Plane for this 3D Vector
144 @return The XZ-Plane Length of the 3D Vector
146 double getXZLength(void) const
148 double fLen((mnX * mnZ) + (mnY * mnZ));
149 if((0 == fLen) || (1.0 == fLen))
150 return fLen;
151 return sqrt(fLen);
154 /** Calculate the length in the YZ-Plane for this 3D Vector
156 @return The YZ-Plane Length of the 3D Vector
158 double getYZLength(void) const
160 double fLen((mnY * mnY) + (mnZ * mnZ));
161 if((0 == fLen) || (1.0 == fLen))
162 return fLen;
163 return sqrt(fLen);
166 /** Set the length of this 3D Vector
168 @param fLen
169 The to be achieved length of the 3D Vector
171 B3IVector& setLength(double fLen)
173 double fLenNow(scalar(*this));
175 if(!::basegfx::fTools::equalZero(fLenNow))
177 const double fOne(1.0);
179 if(!::basegfx::fTools::equal(fOne, fLenNow))
181 fLen /= sqrt(fLenNow);
184 mnX = fround(mnX*fLen);
185 mnY = fround(mnY*fLen);
186 mnZ = fround(mnZ*fLen);
189 return *this;
192 /** Calculate the Scalar product
194 This method calculates the Scalar product between this
195 and the given 3D Vector.
197 @param rVec
198 A second 3D Vector.
200 @return
201 The Scalar Product of two 3D Vectors
203 double scalar(const B3IVector& rVec) const
205 return ((mnX * rVec.mnX) + (mnY * rVec.mnY) + (mnZ * rVec.mnZ));
208 /** Transform vector by given transformation matrix.
210 Since this is a vector, translational components of the
211 matrix are disregarded.
213 B3IVector& operator*=( const B3DHomMatrix& rMat );
216 // external operators
217 //////////////////////////////////////////////////////////////////////////
219 /** Transform vector by given transformation matrix.
221 Since this is a vector, translational components of the
222 matrix are disregarded.
224 BASEGFX_DLLPUBLIC B3IVector operator*( const B3DHomMatrix& rMat, const B3IVector& rVec );
226 /** Calculate the Cross Product of two 3D Vectors
228 @param rVecA
229 A first 3D Vector.
231 @param rVecB
232 A second 3D Vector.
234 @return
235 The Cross Product of both 3D Vectors
237 inline B3IVector cross(const B3IVector& rVecA, const B3IVector& rVecB)
239 B3IVector aVec(
240 rVecA.getY() * rVecB.getZ() - rVecA.getZ() * rVecB.getY(),
241 rVecA.getZ() * rVecB.getX() - rVecA.getX() * rVecB.getZ(),
242 rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
243 return aVec;
245 } // end of namespace basegfx
247 #endif /* _BGFX_VECTOR_B3DVECTOR_HXX */
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */