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_B3DTUPLE_HXX
21 #define INCLUDED_BASEGFX_TUPLE_B3DTUPLE_HXX
23 #include <sal/types.h>
24 #include <basegfx/numeric/ftools.hxx>
25 #include <basegfx/basegfxdllapi.h>
31 /** Base class for all Points/Vectors with three double values
33 This class provides all methods common to Point
34 avd Vector classes which are derived from here.
36 @derive Use this class to implement Points or Vectors
37 which are based on three double values
39 class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DTuple
49 The tuple is initialized to (0.0, 0.0, 0.0)
60 This parameter is used to initialize the X-coordinate
64 This parameter is used to initialize the Y-coordinate
68 This parameter is used to initialize the Z-coordinate
71 B3DTuple(double fX
, double fY
, double fZ
)
77 /// get X-Coordinate of 3D Tuple
83 /// get Y-Coordinate of 3D Tuple
89 /// get Z-Coordinate of 3D Tuple
95 /// set X-Coordinate of 3D Tuple
101 /// set Y-Coordinate of 3D Tuple
107 /// set Z-Coordinate of 3D Tuple
113 /// Array-access to 3D Tuple
114 const double& operator[] (int nPos
) const
116 // Here, normally two if(...)'s should be used. In the assumption that
117 // both double members can be accessed as an array a shortcut is used here.
118 // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
119 return *((&mfX
) + nPos
);
122 /// Array-access to 3D Tuple
123 double& operator[] (int nPos
)
125 // Here, normally two if(...)'s should be used. In the assumption that
126 // both double members can be accessed as an array a shortcut is used here.
127 // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
128 return *((&mfX
) + nPos
);
131 // comparators with tolerance
134 bool equalZero() const
136 return (this == &getEmptyTuple() ||
137 (::basegfx::fTools::equalZero(mfX
)
138 && ::basegfx::fTools::equalZero(mfY
)
139 && ::basegfx::fTools::equalZero(mfZ
)));
142 bool equal(const B3DTuple
& rTup
) const
146 (::basegfx::fTools::equal(mfX
, rTup
.mfX
) &&
147 ::basegfx::fTools::equal(mfY
, rTup
.mfY
) &&
148 ::basegfx::fTools::equal(mfZ
, rTup
.mfZ
)));
154 B3DTuple
& operator+=( const B3DTuple
& rTup
)
162 B3DTuple
& operator-=( const B3DTuple
& rTup
)
170 B3DTuple
& operator/=( const B3DTuple
& rTup
)
178 B3DTuple
& operator*=( const B3DTuple
& rTup
)
186 B3DTuple
& operator*=(double t
)
194 B3DTuple
& operator/=(double t
)
196 const double fVal(1.0 / t
);
203 B3DTuple
operator-(void) const
205 return B3DTuple(-mfX
, -mfY
, -mfZ
);
208 bool operator==( const B3DTuple
& rTup
) const
210 return mfX
== rTup
.mfX
&& mfY
== rTup
.mfY
&& mfZ
== rTup
.mfZ
;
213 bool operator!=( const B3DTuple
& rTup
) const
215 return mfX
!= rTup
.mfX
|| mfY
!= rTup
.mfY
|| mfZ
!= rTup
.mfZ
;
218 void correctValues(const double fCompareValue
= 0.0)
220 if(0.0 == fCompareValue
)
222 if(::basegfx::fTools::equalZero(mfX
))
227 if(::basegfx::fTools::equalZero(mfY
))
232 if(::basegfx::fTools::equalZero(mfZ
))
239 if(::basegfx::fTools::equal(mfX
, fCompareValue
))
244 if(::basegfx::fTools::equal(mfY
, fCompareValue
))
249 if(::basegfx::fTools::equal(mfZ
, fCompareValue
))
256 static const B3DTuple
& getEmptyTuple();
259 // external operators
262 inline B3DTuple
interpolate(const B3DTuple
& rOld1
, const B3DTuple
& rOld2
, double t
)
279 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
280 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY(),
281 ((rOld2
.getZ() - rOld1
.getZ()) * t
) + rOld1
.getZ());
285 inline B3DTuple
average(const B3DTuple
& rOld1
, const B3DTuple
& rOld2
)
288 rtl::math::approxEqual(rOld1
.getX(), rOld2
.getX()) ? rOld1
.getX() : (rOld1
.getX() + rOld2
.getX()) * 0.5,
289 rtl::math::approxEqual(rOld1
.getY(), rOld2
.getY()) ? rOld1
.getY() : (rOld1
.getY() + rOld2
.getY()) * 0.5,
290 rtl::math::approxEqual(rOld1
.getZ(), rOld2
.getZ()) ? rOld1
.getZ() : (rOld1
.getZ() + rOld2
.getZ()) * 0.5);
293 inline B3DTuple
operator+(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
295 B3DTuple
aSum(rTupA
);
300 inline B3DTuple
operator-(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
302 B3DTuple
aSub(rTupA
);
307 inline B3DTuple
operator*(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
309 B3DTuple
aMul(rTupA
);
314 inline B3DTuple
operator*(const B3DTuple
& rTup
, double t
)
321 inline B3DTuple
operator/(const B3DTuple
& rTup
, double t
)
328 /** Round double to nearest integer for 3D tuple
330 @return the nearest integer for this tuple
332 BASEGFX_DLLPUBLIC B3ITuple
fround(const B3DTuple
& rTup
);
333 } // end of namespace basegfx
335 #endif // INCLUDED_BASEGFX_TUPLE_B3DTUPLE_HXX
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */