bump product version to 4.1.6.2
[LibreOffice.git] / include / basegfx / tuple / b3i64tuple.hxx
blobbcc1acaee6b15e03620edcb0294ad6284b19bcab
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_B3I64TUPLE_HXX
21 #define _BGFX_TUPLE_B3I64TUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/tuple/b3dtuple.hxx>
25 #include <basegfx/basegfxdllapi.h>
28 namespace basegfx
30 /** Base class for all Points/Vectors with three sal_Int64 values
32 This class provides all methods common to Point
33 avd Vector classes which are derived from here.
35 @derive Use this class to implement Points or Vectors
36 which are based on three sal_Int64 values
38 class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B3I64Tuple
40 protected:
41 sal_Int64 mnX;
42 sal_Int64 mnY;
43 sal_Int64 mnZ;
45 public:
46 /** Create a 3D Tuple
48 The tuple is initialized to (0, 0, 0)
50 B3I64Tuple()
51 : mnX(0),
52 mnY(0),
53 mnZ(0)
56 /** Create a 3D Tuple
58 @param nX
59 This parameter is used to initialize the X-coordinate
60 of the 3D Tuple.
62 @param nY
63 This parameter is used to initialize the Y-coordinate
64 of the 3D Tuple.
66 @param nZ
67 This parameter is used to initialize the Z-coordinate
68 of the 3D Tuple.
70 B3I64Tuple(sal_Int64 nX, sal_Int64 nY, sal_Int64 nZ)
71 : mnX(nX),
72 mnY(nY),
73 mnZ(nZ)
76 /** Create a copy of a 3D Tuple
78 @param rTup
79 The 3D Tuple which will be copied.
81 B3I64Tuple(const B3I64Tuple& rTup)
82 : mnX( rTup.mnX ),
83 mnY( rTup.mnY ),
84 mnZ( rTup.mnZ )
87 ~B3I64Tuple()
90 /// get X-Coordinate of 3D Tuple
91 sal_Int64 getX() const
93 return mnX;
96 /// get Y-Coordinate of 3D Tuple
97 sal_Int64 getY() const
99 return mnY;
102 /// get Z-Coordinate of 3D Tuple
103 sal_Int64 getZ() const
105 return mnZ;
108 /// set X-Coordinate of 3D Tuple
109 void setX(sal_Int64 nX)
111 mnX = nX;
114 /// set Y-Coordinate of 3D Tuple
115 void setY(sal_Int64 nY)
117 mnY = nY;
120 /// set Z-Coordinate of 3D Tuple
121 void setZ(sal_Int64 nZ)
123 mnZ = nZ;
126 /// Array-access to 3D Tuple
127 const sal_Int64& operator[] (int nPos) const
129 // Here, normally two if(...)'s should be used. In the assumption that
130 // both sal_Int64 members can be accessed as an array a shortcut is used here.
131 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
132 return *((&mnX) + nPos);
135 /// Array-access to 3D Tuple
136 sal_Int64& operator[] (int nPos)
138 // Here, normally two if(...)'s should be used. In the assumption that
139 // both sal_Int64 members can be accessed as an array a shortcut is used here.
140 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
141 return *((&mnX) + nPos);
144 // operators
145 //////////////////////////////////////////////////////////////////////
147 B3I64Tuple& operator+=( const B3I64Tuple& rTup )
149 mnX += rTup.mnX;
150 mnY += rTup.mnY;
151 mnZ += rTup.mnZ;
152 return *this;
155 B3I64Tuple& operator-=( const B3I64Tuple& rTup )
157 mnX -= rTup.mnX;
158 mnY -= rTup.mnY;
159 mnZ -= rTup.mnZ;
160 return *this;
163 B3I64Tuple& operator/=( const B3I64Tuple& rTup )
165 mnX /= rTup.mnX;
166 mnY /= rTup.mnY;
167 mnZ /= rTup.mnZ;
168 return *this;
171 B3I64Tuple& operator*=( const B3I64Tuple& rTup )
173 mnX *= rTup.mnX;
174 mnY *= rTup.mnY;
175 mnZ *= rTup.mnZ;
176 return *this;
179 B3I64Tuple& operator*=(sal_Int64 t)
181 mnX *= t;
182 mnY *= t;
183 mnZ *= t;
184 return *this;
187 B3I64Tuple& operator/=(sal_Int64 t)
189 mnX /= t;
190 mnY /= t;
191 mnZ /= t;
192 return *this;
195 B3I64Tuple operator-(void) const
197 return B3I64Tuple(-mnX, -mnY, -mnZ);
200 bool operator==( const B3I64Tuple& rTup ) const
202 return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY && rTup.mnZ == mnZ);
205 bool operator!=( const B3I64Tuple& rTup ) const
207 return !(*this == rTup);
210 B3I64Tuple& operator=( const B3I64Tuple& rTup )
212 mnX = rTup.mnX;
213 mnY = rTup.mnY;
214 mnZ = rTup.mnZ;
215 return *this;
219 // external operators
220 //////////////////////////////////////////////////////////////////////////
222 inline B3I64Tuple minimum(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
224 B3I64Tuple aMin(
225 (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
226 (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY(),
227 (rTupB.getZ() < rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ());
228 return aMin;
231 inline B3I64Tuple maximum(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
233 B3I64Tuple aMax(
234 (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
235 (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY(),
236 (rTupB.getZ() > rTupA.getZ()) ? rTupB.getZ() : rTupA.getZ());
237 return aMax;
240 inline B3I64Tuple absolute(const B3I64Tuple& rTup)
242 B3I64Tuple aAbs(
243 (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(),
244 (0 > rTup.getY()) ? -rTup.getY() : rTup.getY(),
245 (0 > rTup.getZ()) ? -rTup.getZ() : rTup.getZ());
246 return aAbs;
249 inline B3DTuple interpolate(const B3I64Tuple& rOld1, const B3I64Tuple& rOld2, double t)
251 B3DTuple aInt(
252 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
253 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(),
254 ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ());
255 return aInt;
258 inline B3DTuple average(const B3I64Tuple& rOld1, const B3I64Tuple& rOld2)
260 B3DTuple aAvg(
261 (rOld1.getX() + rOld2.getX()) * 0.5,
262 (rOld1.getY() + rOld2.getY()) * 0.5,
263 (rOld1.getZ() + rOld2.getZ()) * 0.5);
264 return aAvg;
267 inline B3DTuple average(const B3I64Tuple& rOld1, const B3I64Tuple& rOld2, const B3I64Tuple& rOld3)
269 B3DTuple aAvg(
270 (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0),
271 (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0),
272 (rOld1.getZ() + rOld2.getZ() + rOld3.getZ()) * (1.0 / 3.0));
273 return aAvg;
276 inline B3I64Tuple operator+(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
278 B3I64Tuple aSum(rTupA);
279 aSum += rTupB;
280 return aSum;
283 inline B3I64Tuple operator-(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
285 B3I64Tuple aSub(rTupA);
286 aSub -= rTupB;
287 return aSub;
290 inline B3I64Tuple operator/(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
292 B3I64Tuple aDiv(rTupA);
293 aDiv /= rTupB;
294 return aDiv;
297 inline B3I64Tuple operator*(const B3I64Tuple& rTupA, const B3I64Tuple& rTupB)
299 B3I64Tuple aMul(rTupA);
300 aMul *= rTupB;
301 return aMul;
304 inline B3I64Tuple operator*(const B3I64Tuple& rTup, sal_Int64 t)
306 B3I64Tuple aNew(rTup);
307 aNew *= t;
308 return aNew;
311 inline B3I64Tuple operator*(sal_Int64 t, const B3I64Tuple& rTup)
313 B3I64Tuple aNew(rTup);
314 aNew *= t;
315 return aNew;
318 inline B3I64Tuple operator/(const B3I64Tuple& rTup, sal_Int64 t)
320 B3I64Tuple aNew(rTup);
321 aNew /= t;
322 return aNew;
325 inline B3I64Tuple operator/(sal_Int64 t, const B3I64Tuple& rTup)
327 B3I64Tuple aNew(t, t, t);
328 B3I64Tuple aTmp(rTup);
329 aNew /= aTmp;
330 return aNew;
332 } // end of namespace basegfx
334 #endif /* _BGFX_TUPLE_B3I64TUPLE_HXX */
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */