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 INCLUDED_BASEGFX_TUPLE_B3I64TUPLE_HXX
21 #define INCLUDED_BASEGFX_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
);
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
222 inline B3I64Tuple
minimum(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
225 std::min(rTupB
.getX(), rTupA
.getX()),
226 std::min(rTupB
.getY(), rTupA
.getY()),
227 std::min(rTupB
.getZ(), rTupA
.getZ()));
230 inline B3I64Tuple
maximum(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
233 std::max(rTupB
.getX(), rTupA
.getX()),
234 std::max(rTupB
.getY(), rTupA
.getY()),
235 std::max(rTupB
.getZ(), rTupA
.getZ()));
238 inline B3I64Tuple
absolute(const B3I64Tuple
& rTup
)
241 (0 > rTup
.getX()) ? -rTup
.getX() : rTup
.getX(),
242 (0 > rTup
.getY()) ? -rTup
.getY() : rTup
.getY(),
243 (0 > rTup
.getZ()) ? -rTup
.getZ() : rTup
.getZ());
247 inline B3I64Tuple
interpolate(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
, double t
)
264 basegfx::fround64(((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX()),
265 basegfx::fround64(((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY()),
266 basegfx::fround64(((rOld2
.getZ() - rOld1
.getZ()) * t
) + rOld1
.getZ()));
270 inline B3I64Tuple
average(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
)
273 rOld1
.getX() == rOld2
.getX() ? rOld1
.getX() : basegfx::fround64((rOld1
.getX() + rOld2
.getX()) * 0.5),
274 rOld1
.getY() == rOld2
.getY() ? rOld1
.getY() : basegfx::fround64((rOld1
.getY() + rOld2
.getY()) * 0.5),
275 rOld1
.getZ() == rOld2
.getZ() ? rOld1
.getZ() : basegfx::fround64((rOld1
.getZ() + rOld2
.getZ()) * 0.5));
278 inline B3I64Tuple
average(const B3I64Tuple
& rOld1
, const B3I64Tuple
& rOld2
, const B3I64Tuple
& rOld3
)
281 (rOld1
.getX() == rOld2
.getX() && rOld2
.getX() == rOld3
.getX()) ? rOld1
.getX() : basegfx::fround64((rOld1
.getX() + rOld2
.getX() + rOld3
.getX()) * (1.0 / 3.0)),
282 (rOld1
.getY() == rOld2
.getY() && rOld2
.getY() == rOld3
.getY()) ? rOld1
.getY() : basegfx::fround64((rOld1
.getY() + rOld2
.getY() + rOld3
.getY()) * (1.0 / 3.0)),
283 (rOld1
.getZ() == rOld2
.getZ() && rOld2
.getZ() == rOld3
.getZ()) ? rOld1
.getZ() : basegfx::fround64((rOld1
.getZ() + rOld2
.getZ() + rOld3
.getZ()) * (1.0 / 3.0)));
286 inline B3I64Tuple
operator+(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
288 B3I64Tuple
aSum(rTupA
);
293 inline B3I64Tuple
operator-(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
295 B3I64Tuple
aSub(rTupA
);
300 inline B3I64Tuple
operator/(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
302 B3I64Tuple
aDiv(rTupA
);
307 inline B3I64Tuple
operator*(const B3I64Tuple
& rTupA
, const B3I64Tuple
& rTupB
)
309 B3I64Tuple
aMul(rTupA
);
314 inline B3I64Tuple
operator*(const B3I64Tuple
& rTup
, sal_Int64 t
)
316 B3I64Tuple
aNew(rTup
);
321 inline B3I64Tuple
operator*(sal_Int64 t
, const B3I64Tuple
& rTup
)
323 B3I64Tuple
aNew(rTup
);
328 inline B3I64Tuple
operator/(const B3I64Tuple
& rTup
, sal_Int64 t
)
330 B3I64Tuple
aNew(rTup
);
335 inline B3I64Tuple
operator/(sal_Int64 t
, const B3I64Tuple
& rTup
)
337 B3I64Tuple
aNew(t
, t
, t
);
338 B3I64Tuple
aTmp(rTup
);
342 } // end of namespace basegfx
344 #endif // INCLUDED_BASEGFX_TUPLE_B3I64TUPLE_HXX
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */