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 _BGFX_VECTOR_B3IVECTOR_HXX
21 #define _BGFX_VECTOR_B3IVECTOR_HXX
23 #include <basegfx/tuple/b3ituple.hxx>
24 #include <basegfx/basegfxdllapi.h>
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.
39 class BASEGFX_DLLPUBLIC B3IVector
: public ::basegfx::B3ITuple
42 /** Create a 3D Vector
44 The vector is initialized to (0, 0, 0)
50 /** Create a 3D Vector
53 This parameter is used to initialize the X-coordinate
57 This parameter is used to initialize the Y-coordinate
61 This parameter is used to initialize the Z-coordinate
64 B3IVector(sal_Int32 nX
, sal_Int32 nY
, sal_Int32 nZ
)
65 : B3ITuple(nX
, nY
, nZ
)
68 /** Create a copy of a 3D Vector
71 The 3D Vector which will be copied.
73 B3IVector(const B3IVector
& rVec
)
77 /** constructor with tuple to allow copy-constructing
78 from B3ITuple-based classes
80 B3IVector(const ::basegfx::B3ITuple
& rTuple
)
87 /** *=operator to allow usage from B3IVector, too
89 B3IVector
& operator*=( const B3IVector
& rPnt
)
97 /** *=operator to allow usage from B3IVector, too
99 B3IVector
& operator*=(sal_Int32 t
)
107 /** assignment operator to allow assigning the results
108 of B3ITuple calculations
110 B3IVector
& operator=( const ::basegfx::B3ITuple
& rVec
)
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
))
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
))
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
))
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
))
166 /** Set the length of this 3D Vector
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
);
192 /** Calculate the Scalar product
194 This method calculates the Scalar product between this
195 and the given 3D Vector.
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
235 The Cross Product of both 3D Vectors
237 inline B3IVector
cross(const B3IVector
& rVecA
, const B3IVector
& rVecB
)
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());
245 } // end of namespace basegfx
247 #endif /* _BGFX_VECTOR_B3DVECTOR_HXX */
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */