tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / basegfx / tuple / b3dtuple.hxx
blob2701b2f25c4feab36a26eaefd4dee8dfb0a8d80a
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 <sal/types.h>
23 #include <basegfx/numeric/ftools.hxx>
24 #include <basegfx/basegfxdllapi.h>
25 #include <basegfx/tuple/Tuple3D.hxx>
27 namespace basegfx
29 class B3ITuple;
31 /** Base class for all Points/Vectors with three double values
33 This class provides all methods common to Point
34 and Vector classes which are derived from here.
36 @derive Use this class to implement Points or Vectors
37 which are based on three double values
39 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DTuple : public Tuple3D<double>
41 public:
42 /** Create a 3D Tuple
44 The tuple is initialized to (0.0, 0.0, 0.0)
46 B3DTuple()
47 : Tuple3D(0.0, 0.0, 0.0)
50 /** Create a 3D Tuple
52 @param fX
53 This parameter is used to initialize the X-coordinate
54 of the 3D Tuple.
56 @param fY
57 This parameter is used to initialize the Y-coordinate
58 of the 3D Tuple.
60 @param fZ
61 This parameter is used to initialize the Z-coordinate
62 of the 3D Tuple.
64 B3DTuple(double fX, double fY, double fZ)
65 : Tuple3D(fX, fY, fZ)
68 /// Array-access to 3D Tuple
69 const double& operator[] (int nPos) const
71 // Here, normally two if(...)'s should be used. In the assumption that
72 // both double members can be accessed as an array a shortcut is used here.
73 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
74 return *((&mnX) + nPos);
77 /// Array-access to 3D Tuple
78 double& operator[] (int nPos)
80 // Here, normally two if(...)'s should be used. In the assumption that
81 // both double members can be accessed as an array a shortcut is used here.
82 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
83 return *((&mnX) + nPos);
86 // comparators with tolerance
89 bool equalZero() const
91 return (this == &getEmptyTuple() ||
92 (::basegfx::fTools::equalZero(mnX)
93 && ::basegfx::fTools::equalZero(mnY)
94 && ::basegfx::fTools::equalZero(mnZ)));
97 bool equal(const B3DTuple& rTup) const
99 return (
100 this == &rTup ||
101 (::basegfx::fTools::equal(mnX, rTup.mnX) &&
102 ::basegfx::fTools::equal(mnY, rTup.mnY) &&
103 ::basegfx::fTools::equal(mnZ, rTup.mnZ)));
106 // operators
108 B3DTuple operator-(void) const
110 return B3DTuple(-mnX, -mnY, -mnZ);
113 bool operator==(const B3DTuple& rTup) const
115 return ::basegfx::fTools::equal(mnX, rTup.mnX) &&
116 ::basegfx::fTools::equal(mnY, rTup.mnY) &&
117 ::basegfx::fTools::equal(mnZ, rTup.mnZ);
120 bool operator!=(const B3DTuple& rTup) const { return !operator==(rTup); }
122 void correctValues(const double fCompareValue = 0.0)
124 if(0.0 == fCompareValue)
126 if(::basegfx::fTools::equalZero(mnX))
128 mnX = 0.0;
131 if(::basegfx::fTools::equalZero(mnY))
133 mnY = 0.0;
136 if(::basegfx::fTools::equalZero(mnZ))
138 mnZ = 0.0;
141 else
143 if(::basegfx::fTools::equal(mnX, fCompareValue))
145 mnX = fCompareValue;
148 if(::basegfx::fTools::equal(mnY, fCompareValue))
150 mnY = fCompareValue;
153 if(::basegfx::fTools::equal(mnZ, fCompareValue))
155 mnZ = fCompareValue;
160 static const B3DTuple& getEmptyTuple();
163 // external operators
166 inline B3DTuple interpolate(const B3DTuple& rOld1, const B3DTuple& rOld2, double t)
168 if(rOld1 == rOld2)
170 return rOld1;
172 else if(0.0 >= t)
174 return rOld1;
176 else if(1.0 <= t)
178 return rOld2;
180 else
182 return B3DTuple(
183 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
184 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(),
185 ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ());
189 inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2)
191 return B3DTuple(
192 rtl_math_approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
193 rtl_math_approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5,
194 rtl_math_approxEqual(rOld1.getZ(), rOld2.getZ()) ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
197 inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB)
199 B3DTuple aSum(rTupA);
200 aSum += rTupB;
201 return aSum;
204 inline B3DTuple operator-(const B3DTuple& rTupA, const B3DTuple& rTupB)
206 B3DTuple aSub(rTupA);
207 aSub -= rTupB;
208 return aSub;
211 inline B3DTuple operator*(const B3DTuple& rTupA, const B3DTuple& rTupB)
213 B3DTuple aMul(rTupA);
214 aMul *= rTupB;
215 return aMul;
218 inline B3DTuple operator*(const B3DTuple& rTup, double t)
220 B3DTuple aNew(rTup);
221 aNew *= t;
222 return aNew;
225 inline B3DTuple operator/(const B3DTuple& rTup, double t)
227 B3DTuple aNew(rTup);
228 aNew /= t;
229 return aNew;
232 /** Round double to nearest integer for 3D tuple
234 @return the nearest integer for this tuple
236 BASEGFX_DLLPUBLIC B3ITuple fround(const B3DTuple& rTup);
237 } // end of namespace basegfx
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */