bump product version to 4.1.6.2
[LibreOffice.git] / include / basegfx / tuple / b3ituple.hxx
blob49fb24634ed44a90205c4c10b56586080db45e23
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_TUPLE_B3ITUPLE_HXX
21 #define _BGFX_TUPLE_B3ITUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/tuple/b3dtuple.hxx>
25 #include <basegfx/basegfxdllapi.h>
27 namespace basegfx
29 /** Base class for all Points/Vectors with three sal_Int32 values
31 This class provides all methods common to Point
32 avd Vector classes which are derived from here.
34 @derive Use this class to implement Points or Vectors
35 which are based on three sal_Int32 values
37 class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B3ITuple
39 protected:
40 sal_Int32 mnX;
41 sal_Int32 mnY;
42 sal_Int32 mnZ;
44 public:
45 /** Create a 3D Tuple
47 The tuple is initialized to (0, 0, 0)
49 B3ITuple()
50 : mnX(0),
51 mnY(0),
52 mnZ(0)
55 /** Create a 3D Tuple
57 @param nX
58 This parameter is used to initialize the X-coordinate
59 of the 3D Tuple.
61 @param nY
62 This parameter is used to initialize the Y-coordinate
63 of the 3D Tuple.
65 @param nZ
66 This parameter is used to initialize the Z-coordinate
67 of the 3D Tuple.
69 B3ITuple(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ)
70 : mnX(nX),
71 mnY(nY),
72 mnZ(nZ)
75 /** Create a copy of a 3D Tuple
77 @param rTup
78 The 3D Tuple which will be copied.
80 B3ITuple(const B3ITuple& rTup)
81 : mnX( rTup.mnX ),
82 mnY( rTup.mnY ),
83 mnZ( rTup.mnZ )
86 ~B3ITuple()
89 /// get X-Coordinate of 3D Tuple
90 sal_Int32 getX() const
92 return mnX;
95 /// get Y-Coordinate of 3D Tuple
96 sal_Int32 getY() const
98 return mnY;
101 /// get Z-Coordinate of 3D Tuple
102 sal_Int32 getZ() const
104 return mnZ;
107 /// set X-Coordinate of 3D Tuple
108 void setX(sal_Int32 nX)
110 mnX = nX;
113 /// set Y-Coordinate of 3D Tuple
114 void setY(sal_Int32 nY)
116 mnY = nY;
119 /// set Z-Coordinate of 3D Tuple
120 void setZ(sal_Int32 nZ)
122 mnZ = nZ;
125 /// Array-access to 3D Tuple
126 const sal_Int32& operator[] (int nPos) const
128 // Here, normally two if(...)'s should be used. In the assumption that
129 // both sal_Int32 members can be accessed as an array a shortcut is used here.
130 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
131 return *((&mnX) + nPos);
134 /// Array-access to 3D Tuple
135 sal_Int32& operator[] (int nPos)
137 // Here, normally two if(...)'s should be used. In the assumption that
138 // both sal_Int32 members can be accessed as an array a shortcut is used here.
139 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
140 return *((&mnX) + nPos);
143 // operators
144 //////////////////////////////////////////////////////////////////////
146 B3ITuple& operator+=( const B3ITuple& rTup )
148 mnX += rTup.mnX;
149 mnY += rTup.mnY;
150 mnZ += rTup.mnZ;
151 return *this;
154 B3ITuple& operator-=( const B3ITuple& rTup )
156 mnX -= rTup.mnX;
157 mnY -= rTup.mnY;
158 mnZ -= rTup.mnZ;
159 return *this;
162 B3ITuple& operator/=( const B3ITuple& rTup )
164 mnX /= rTup.mnX;
165 mnY /= rTup.mnY;
166 mnZ /= rTup.mnZ;
167 return *this;
170 B3ITuple& operator*=( const B3ITuple& rTup )
172 mnX *= rTup.mnX;
173 mnY *= rTup.mnY;
174 mnZ *= rTup.mnZ;
175 return *this;
178 B3ITuple& operator*=(sal_Int32 t)
180 mnX *= t;
181 mnY *= t;
182 mnZ *= t;
183 return *this;
186 B3ITuple& operator/=(sal_Int32 t)
188 mnX /= t;
189 mnY /= t;
190 mnZ /= t;
191 return *this;
194 B3ITuple operator-(void) const
196 return B3ITuple(-mnX, -mnY, -mnZ);
199 bool operator==( const B3ITuple& rTup ) const
201 return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY && rTup.mnZ == mnZ);
204 bool operator!=( const B3ITuple& rTup ) const
206 return !(*this == rTup);
209 B3ITuple& operator=( const B3ITuple& rTup )
211 mnX = rTup.mnX;
212 mnY = rTup.mnY;
213 mnZ = rTup.mnZ;
214 return *this;
218 // external operators
219 //////////////////////////////////////////////////////////////////////////
221 inline B3ITuple minimum(const B3ITuple& rTupA, const B3ITuple& rTupB)
223 B3ITuple aMin(
224 (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
225 (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY(),
226 (rTupB.getZ() < rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ());
227 return aMin;
230 inline B3ITuple maximum(const B3ITuple& rTupA, const B3ITuple& rTupB)
232 B3ITuple aMax(
233 (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
234 (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY(),
235 (rTupB.getZ() > rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ());
236 return aMax;
239 inline B3ITuple absolute(const B3ITuple& rTup)
241 B3ITuple aAbs(
242 (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(),
243 (0 > rTup.getY()) ? -rTup.getY() : rTup.getY(),
244 (0 > rTup.getZ()) ? -rTup.getZ() : rTup.getZ());
245 return aAbs;
248 inline B3DTuple interpolate(const B3ITuple& rOld1, const B3ITuple& rOld2, double t)
250 B3DTuple aInt(
251 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
252 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(),
253 ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ());
254 return aInt;
257 inline B3DTuple average(const B3ITuple& rOld1, const B3ITuple& rOld2)
259 B3DTuple aAvg(
260 (rOld1.getX() + rOld2.getX()) * 0.5,
261 (rOld1.getY() + rOld2.getY()) * 0.5,
262 (rOld1.getZ() + rOld2.getZ()) * 0.5);
263 return aAvg;
266 inline B3DTuple average(const B3ITuple& rOld1, const B3ITuple& rOld2, const B3ITuple& rOld3)
268 B3DTuple aAvg(
269 (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0),
270 (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0),
271 (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0));
272 return aAvg;
275 inline B3ITuple operator+(const B3ITuple& rTupA, const B3ITuple& rTupB)
277 B3ITuple aSum(rTupA);
278 aSum += rTupB;
279 return aSum;
282 inline B3ITuple operator-(const B3ITuple& rTupA, const B3ITuple& rTupB)
284 B3ITuple aSub(rTupA);
285 aSub -= rTupB;
286 return aSub;
289 inline B3ITuple operator/(const B3ITuple& rTupA, const B3ITuple& rTupB)
291 B3ITuple aDiv(rTupA);
292 aDiv /= rTupB;
293 return aDiv;
296 inline B3ITuple operator*(const B3ITuple& rTupA, const B3ITuple& rTupB)
298 B3ITuple aMul(rTupA);
299 aMul *= rTupB;
300 return aMul;
303 inline B3ITuple operator*(const B3ITuple& rTup, sal_Int32 t)
305 B3ITuple aNew(rTup);
306 aNew *= t;
307 return aNew;
310 inline B3ITuple operator*(sal_Int32 t, const B3ITuple& rTup)
312 B3ITuple aNew(rTup);
313 aNew *= t;
314 return aNew;
317 inline B3ITuple operator/(const B3ITuple& rTup, sal_Int32 t)
319 B3ITuple aNew(rTup);
320 aNew /= t;
321 return aNew;
324 inline B3ITuple operator/(sal_Int32 t, const B3ITuple& rTup)
326 B3ITuple aNew(t, t, t);
327 B3ITuple aTmp(rTup);
328 aNew /= aTmp;
329 return aNew;
331 } // end of namespace basegfx
333 #endif /* _BGFX_TUPLE_B3ITUPLE_HXX */
335 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */