LibreOffice Module basegfx (master) 1
b3dvector.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
24
25namespace basegfx
26{
27 class B3DHomMatrix;
28
38 {
39 public:
45 {}
46
61 B3DVector(double fX, double fY, double fZ)
62 : B3DTuple(fX, fY, fZ)
63 {}
64
68 B3DVector(const ::basegfx::B3DTuple& rTuple)
69 : B3DTuple(rTuple)
70 {}
71
75 {
76 mfX *= rPnt.mfX;
77 mfY *= rPnt.mfY;
78 mfZ *= rPnt.mfZ;
79 return *this;
80 }
81
85 {
86 mfX *= t;
87 mfY *= t;
88 mfZ *= t;
89 return *this;
90 }
91
95 B3DVector& operator=( const ::basegfx::B3DTuple& rVec )
96 {
97 mfX = rVec.getX();
98 mfY = rVec.getY();
99 mfZ = rVec.getZ();
100 return *this;
101 }
102
107 double getLength() const
108 {
109 double fLen(scalar(*this));
110 if((0.0 == fLen) || (1.0 == fLen))
111 return fLen;
112 return sqrt(fLen);
113 }
114
119 double getXZLength() const
120 {
121 double fLen((mfX * mfX) + (mfZ * mfZ)); // #i73040#
122 if((0.0 == fLen) || (1.0 == fLen))
123 return fLen;
124 return sqrt(fLen);
125 }
126
131 double getYZLength() const
132 {
133 double fLen((mfY * mfY) + (mfZ * mfZ));
134 if((0.0 == fLen) || (1.0 == fLen))
135 return fLen;
136 return sqrt(fLen);
137 }
138
144 B3DVector& setLength(double fLen)
145 {
146 double fLenNow(scalar(*this));
147
148 if(!::basegfx::fTools::equalZero(fLenNow))
149 {
150 const double fOne(1.0);
151
152 if(!::basegfx::fTools::equal(fOne, fLenNow))
153 {
154 fLen /= sqrt(fLenNow);
155 }
156
157 mfX *= fLen;
158 mfY *= fLen;
159 mfZ *= fLen;
160 }
161
162 return *this;
163 }
164
170
182 B3DVector getPerpendicular(const B3DVector& rNormalizedVec) const;
183
195 double scalar(const B3DVector& rVec) const
196 {
197 return ((mfX * rVec.mfX) + (mfY * rVec.mfY) + (mfZ * rVec.mfZ));
198 }
199
206
207 static const B3DVector& getEmptyVector()
208 {
209 return static_cast<const B3DVector&>( ::basegfx::B3DTuple::getEmptyTuple() );
210 }
211 };
212
213 // external operators
214
215
228 BASEGFX_DLLPUBLIC bool areParallel( const B3DVector& rVecA, const B3DVector& rVecB );
229
236
248 inline B3DVector cross(const B3DVector& rVecA, const B3DVector& rVecB)
249 {
250 B3DVector aVec(
251 rVecA.getY() * rVecB.getZ() - rVecA.getZ() * rVecB.getY(),
252 rVecA.getZ() * rVecB.getX() - rVecA.getX() * rVecB.getZ(),
253 rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
254 return aVec;
255 }
256} // end of namespace basegfx
257
258/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
#define BASEGFX_DLLPUBLIC
Definition: basegfxdllapi.h:35
Base class for all Points/Vectors with three double values.
Definition: b3dtuple.hxx:40
static const B3DTuple & getEmptyTuple()
Definition: b3dtuple.cxx:25
Base Point class with three double values.
Definition: b3dvector.hxx:38
double getLength() const
Calculate the length of this 3D Vector.
Definition: b3dvector.hxx:107
B3DVector & setLength(double fLen)
Set the length of this 3D Vector.
Definition: b3dvector.hxx:144
B3DVector & operator=(const ::basegfx::B3DTuple &rVec)
assignment operator to allow assigning the results of B3DTuple calculations
Definition: b3dvector.hxx:95
B3DVector(const ::basegfx::B3DTuple &rTuple)
constructor with tuple to allow copy-constructing from B3DTuple-based classes
Definition: b3dvector.hxx:68
B3DVector(double fX, double fY, double fZ)
Create a 3D Vector.
Definition: b3dvector.hxx:61
B3DVector & operator*=(double t)
*=operator to allow usage from B3DVector, too
Definition: b3dvector.hxx:84
double getXZLength() const
Calculate the length in the XZ-Plane for this 3D Vector.
Definition: b3dvector.hxx:119
double getYZLength() const
Calculate the length in the YZ-Plane for this 3D Vector.
Definition: b3dvector.hxx:131
static const B3DVector & getEmptyVector()
Definition: b3dvector.hxx:207
B3DVector()
Create a 3D Vector.
Definition: b3dvector.hxx:44
B3DVector & operator*=(const B3DHomMatrix &rMat)
Transform vector by given transformation matrix.
double scalar(const B3DVector &rVec) const
Calculate the Scalar product.
Definition: b3dvector.hxx:195
B3DVector & operator*=(const B3DVector &rPnt)
*=operator to allow usage from B3DVector, too
Definition: b3dvector.hxx:74
TYPE getX() const
Get X-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:57
TYPE getZ() const
Get Z-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:63
TYPE getY() const
Get Y-Coordinate of 3D Tuple.
Definition: Tuple3D.hxx:60
bool equalZero(const T &rfVal)
Compare against small value.
Definition: ftools.hxx:156
bool areParallel(const B2DVector &rVecA, const B2DVector &rVecB)
Test two vectors which need not to be normalized for parallelism.
Definition: b2dvector.cxx:111
B3DVector cross(const B3DVector &rVecA, const B3DVector &rVecB)
Calculate the Cross Product of two 3D Vectors.
Definition: b3dvector.hxx:248
B2DVector getPerpendicular(const B2DVector &rNormalizedVec)
Calculate a perpendicular 2D Vector to the given one.
Definition: b2dvector.cxx:138
B2DPoint operator*(const ::basegfx::B2DHomMatrix &rMat, const B2DPoint &rPoint)
Definition: b2dpoint.cxx:43
bool normalize(sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
double mfY
double mfX
#define SAL_WARN_UNUSED