1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
48 The tuple is initialized to (0, 0, 0)
59 This parameter is used to initialize the X-coordinate
63 This parameter is used to initialize the Y-coordinate
67 This parameter is used to initialize the Z-coordinate
70 B3I64Tuple(sal_Int64 nX
, sal_Int64 nY
, sal_Int64 nZ
)
76 /** Create a copy of a 3D Tuple
79 The 3D Tuple which will be copied.
81 B3I64Tuple(const B3I64Tuple
& rTup
)
90 /// get X-Coordinate of 3D Tuple
91 sal_Int64
getX() const
96 /// get Y-Coordinate of 3D Tuple
97 sal_Int64
getY() const
102 /// get Z-Coordinate of 3D Tuple
103 sal_Int64
getZ() const
108 /// set X-Coordinate of 3D Tuple
109 void setX(sal_Int64 nX
)
114 /// set Y-Coordinate of 3D Tuple
115 void setY(sal_Int64 nY
)
120 /// set Z-Coordinate of 3D Tuple
121 void setZ(sal_Int64 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
);
145 //////////////////////////////////////////////////////////////////////
147 B3I64Tuple
& operator+=( const B3I64Tuple
& rTup
)
155 B3I64Tuple
& operator-=( const B3I64Tuple
& rTup
)
163 B3I64Tuple
& operator/=( const B3I64Tuple
& rTup
)
171 B3I64Tuple
& operator*=( const B3I64Tuple
& rTup
)
179 B3I64Tuple
& operator*=(sal_Int64 t
)
187 B3I64Tuple
& operator/=(sal_Int64 t
)
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
)
219 // external operators
220 //////////////////////////////////////////////////////////////////////////
222 inline B3I64Tuple
minimum(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
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());
231 inline B3I64Tuple
maximum(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
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());
240 inline B3I64Tuple
absolute(const B3I64Tuple
& rTup
)
243 (0 > rTup
.getX()) ? -rTup
.getX() : rTup
.getX(),
244 (0 > rTup
.getY()) ? -rTup
.getY() : rTup
.getY(),
245 (0 > rTup
.getZ()) ? -rTup
.getZ() : rTup
.getZ());
249 inline B3DTuple
interpolate(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
, double t
)
252 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
253 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY(),
254 ((rOld2
.getZ() - rOld1
.getZ()) * t
) + rOld1
.getZ());
258 inline B3DTuple
average(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
)
261 (rOld1
.getX() + rOld2
.getX()) * 0.5,
262 (rOld1
.getY() + rOld2
.getY()) * 0.5,
263 (rOld1
.getZ() + rOld2
.getZ()) * 0.5);
267 inline B3DTuple
average(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
, const B3I64Tuple
& rOld3
)
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));
276 inline B3I64Tuple
operator+(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
278 B3I64Tuple
aSum(rTupA
);
283 inline B3I64Tuple
operator-(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
285 B3I64Tuple
aSub(rTupA
);
290 inline B3I64Tuple
operator/(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
292 B3I64Tuple
aDiv(rTupA
);
297 inline B3I64Tuple
operator*(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
299 B3I64Tuple
aMul(rTupA
);
304 inline B3I64Tuple
operator*(const B3I64Tuple
& rTup
, sal_Int64 t
)
306 B3I64Tuple
aNew(rTup
);
311 inline B3I64Tuple
operator*(sal_Int64 t
, const B3I64Tuple
& rTup
)
313 B3I64Tuple
aNew(rTup
);
318 inline B3I64Tuple
operator/(const B3I64Tuple
& rTup
, sal_Int64 t
)
320 B3I64Tuple
aNew(rTup
);
325 inline B3I64Tuple
operator/(sal_Int64 t
, const B3I64Tuple
& rTup
)
327 B3I64Tuple
aNew(t
, t
, t
);
328 B3I64Tuple
aTmp(rTup
);
332 } // end of namespace basegfx
334 #endif /* _BGFX_TUPLE_B3I64TUPLE_HXX */
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */