bump product version to 4.1.6.2
[LibreOffice.git] / include / basegfx / tuple / b2i64tuple.hxx
blobdebb4cabe5781ade36310236be08f9b72f839509
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_B2I64TUPLE_HXX
21 #define _BGFX_TUPLE_B2I64TUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/tuple/b2dtuple.hxx>
25 #include <basegfx/basegfxdllapi.h>
28 namespace basegfx
30 /** Base class for all Points/Vectors with two 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 two sal_Int64 values
38 class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED B2I64Tuple
40 protected:
41 sal_Int64 mnX;
42 sal_Int64 mnY;
44 public:
45 /** Create a 2D Tuple
47 The tuple is initialized to (0, 0)
49 B2I64Tuple()
50 : mnX(0),
51 mnY(0)
54 /** Create a 2D Tuple
56 @param fX
57 This parameter is used to initialize the X-coordinate
58 of the 2D Tuple.
60 @param fY
61 This parameter is used to initialize the Y-coordinate
62 of the 2D Tuple.
64 B2I64Tuple(sal_Int64 fX, sal_Int64 fY)
65 : mnX( fX ),
66 mnY( fY )
69 /** Create a copy of a 2D Tuple
71 @param rTup
72 The 2D Tuple which will be copied.
74 B2I64Tuple(const B2I64Tuple& rTup)
75 : mnX( rTup.mnX ),
76 mnY( rTup.mnY )
79 ~B2I64Tuple()
82 /// Get X-Coordinate of 2D Tuple
83 sal_Int64 getX() const
85 return mnX;
88 /// Get Y-Coordinate of 2D Tuple
89 sal_Int64 getY() const
91 return mnY;
94 /// Set X-Coordinate of 2D Tuple
95 void setX(sal_Int64 fX)
97 mnX = fX;
100 /// Set Y-Coordinate of 2D Tuple
101 void setY(sal_Int64 fY)
103 mnY = fY;
106 /// Array-access to 2D Tuple
107 const sal_Int64& operator[] (int nPos) const
109 // Here, normally one if(...) should be used. In the assumption that
110 // both sal_Int64 members can be accessed as an array a shortcut is used here.
111 // if(0 == nPos) return mnX; return mnY;
112 return *((&mnX) + nPos);
115 /// Array-access to 2D Tuple
116 sal_Int64& operator[] (int nPos)
118 // Here, normally one if(...) should be used. In the assumption that
119 // both sal_Int64 members can be accessed as an array a shortcut is used here.
120 // if(0 == nPos) return mnX; return mnY;
121 return *((&mnX) + nPos);
124 // operators
125 //////////////////////////////////////////////////////////////////////
127 B2I64Tuple& operator+=( const B2I64Tuple& rTup )
129 mnX += rTup.mnX;
130 mnY += rTup.mnY;
131 return *this;
134 B2I64Tuple& operator-=( const B2I64Tuple& rTup )
136 mnX -= rTup.mnX;
137 mnY -= rTup.mnY;
138 return *this;
141 B2I64Tuple& operator/=( const B2I64Tuple& rTup )
143 mnX /= rTup.mnX;
144 mnY /= rTup.mnY;
145 return *this;
148 B2I64Tuple& operator*=( const B2I64Tuple& rTup )
150 mnX *= rTup.mnX;
151 mnY *= rTup.mnY;
152 return *this;
155 B2I64Tuple& operator*=(sal_Int64 t)
157 mnX *= t;
158 mnY *= t;
159 return *this;
162 B2I64Tuple& operator/=(sal_Int64 t)
164 mnX /= t;
165 mnY /= t;
166 return *this;
169 B2I64Tuple operator-(void) const
171 return B2I64Tuple(-mnX, -mnY);
174 bool equalZero() const { return mnX == 0 && mnY == 0; }
176 bool operator==( const B2I64Tuple& rTup ) const
178 return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
181 bool operator!=( const B2I64Tuple& rTup ) const
183 return !(*this == rTup);
186 B2I64Tuple& operator=( const B2I64Tuple& rTup )
188 mnX = rTup.mnX;
189 mnY = rTup.mnY;
190 return *this;
194 // external operators
195 //////////////////////////////////////////////////////////////////////////
197 inline B2I64Tuple minimum(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
199 B2I64Tuple aMin(
200 (rTupB.getX() < rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
201 (rTupB.getY() < rTupA.getY()) ? rTupB.getY() : rTupA.getY());
202 return aMin;
205 inline B2I64Tuple maximum(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
207 B2I64Tuple aMax(
208 (rTupB.getX() > rTupA.getX()) ? rTupB.getX() : rTupA.getX(),
209 (rTupB.getY() > rTupA.getY()) ? rTupB.getY() : rTupA.getY());
210 return aMax;
213 inline B2I64Tuple absolute(const B2I64Tuple& rTup)
215 B2I64Tuple aAbs(
216 (0 > rTup.getX()) ? -rTup.getX() : rTup.getX(),
217 (0 > rTup.getY()) ? -rTup.getY() : rTup.getY());
218 return aAbs;
221 inline B2DTuple interpolate(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2, double t)
223 B2DTuple aInt(
224 ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
225 ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY());
226 return aInt;
229 inline B2DTuple average(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2)
231 B2DTuple aAvg(
232 (rOld1.getX() + rOld2.getX()) * 0.5,
233 (rOld1.getY() + rOld2.getY()) * 0.5);
234 return aAvg;
237 inline B2DTuple average(const B2I64Tuple& rOld1, const B2I64Tuple& rOld2, const B2I64Tuple& rOld3)
239 B2DTuple aAvg(
240 (rOld1.getX() + rOld2.getX() + rOld3.getX()) * (1.0 / 3.0),
241 (rOld1.getY() + rOld2.getY() + rOld3.getY()) * (1.0 / 3.0));
242 return aAvg;
245 inline B2I64Tuple operator+(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
247 B2I64Tuple aSum(rTupA);
248 aSum += rTupB;
249 return aSum;
252 inline B2I64Tuple operator-(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
254 B2I64Tuple aSub(rTupA);
255 aSub -= rTupB;
256 return aSub;
259 inline B2I64Tuple operator/(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
261 B2I64Tuple aDiv(rTupA);
262 aDiv /= rTupB;
263 return aDiv;
266 inline B2I64Tuple operator*(const B2I64Tuple& rTupA, const B2I64Tuple& rTupB)
268 B2I64Tuple aMul(rTupA);
269 aMul *= rTupB;
270 return aMul;
273 inline B2I64Tuple operator*(const B2I64Tuple& rTup, sal_Int64 t)
275 B2I64Tuple aNew(rTup);
276 aNew *= t;
277 return aNew;
280 inline B2I64Tuple operator*(sal_Int64 t, const B2I64Tuple& rTup)
282 B2I64Tuple aNew(rTup);
283 aNew *= t;
284 return aNew;
287 inline B2I64Tuple operator/(const B2I64Tuple& rTup, sal_Int64 t)
289 B2I64Tuple aNew(rTup);
290 aNew /= t;
291 return aNew;
294 inline B2I64Tuple operator/(sal_Int64 t, const B2I64Tuple& rTup)
296 B2I64Tuple aNew(t, t);
297 B2I64Tuple aTmp(rTup);
298 aNew /= aTmp;
299 return aNew;
301 } // end of namespace basegfx
303 #endif /* _BGFX_TUPLE_B2I64TUPLE_HXX */
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */