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 .
22 #include <sal/types.h>
23 #include <basegfx/numeric/ftools.hxx>
24 #include <basegfx/basegfxdllapi.h>
25 #include <basegfx/tuple/Tuple3D.hxx>
31 /** Base class for all Points/Vectors with three double values
33 This class provides all methods common to Point
34 and 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
: public Tuple3D
<double>
44 The tuple is initialized to (0.0, 0.0, 0.0)
47 : Tuple3D(0.0, 0.0, 0.0)
53 This parameter is used to initialize the X-coordinate
57 This parameter is used to initialize the Y-coordinate
61 This parameter is used to initialize the Z-coordinate
64 B3DTuple(double fX
, double fY
, double fZ
)
68 /// Array-access to 3D Tuple
69 const double& operator[] (int nPos
) const
71 // Here, normally two if(...)'s should be used. In the assumption that
72 // both double members can be accessed as an array a shortcut is used here.
73 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
74 return *((&mnX
) + nPos
);
77 /// Array-access to 3D Tuple
78 double& operator[] (int nPos
)
80 // Here, normally two if(...)'s should be used. In the assumption that
81 // both double members can be accessed as an array a shortcut is used here.
82 // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
83 return *((&mnX
) + nPos
);
86 // comparators with tolerance
89 bool equalZero() const
91 return (this == &getEmptyTuple() ||
92 (::basegfx::fTools::equalZero(mnX
)
93 && ::basegfx::fTools::equalZero(mnY
)
94 && ::basegfx::fTools::equalZero(mnZ
)));
97 bool equal(const B3DTuple
& rTup
) const
101 (::basegfx::fTools::equal(mnX
, rTup
.mnX
) &&
102 ::basegfx::fTools::equal(mnY
, rTup
.mnY
) &&
103 ::basegfx::fTools::equal(mnZ
, rTup
.mnZ
)));
108 B3DTuple
operator-(void) const
110 return B3DTuple(-mnX
, -mnY
, -mnZ
);
113 bool operator==(const B3DTuple
& rTup
) const
115 return ::basegfx::fTools::equal(mnX
, rTup
.mnX
) &&
116 ::basegfx::fTools::equal(mnY
, rTup
.mnY
) &&
117 ::basegfx::fTools::equal(mnZ
, rTup
.mnZ
);
120 bool operator!=(const B3DTuple
& rTup
) const { return !operator==(rTup
); }
122 void correctValues(const double fCompareValue
= 0.0)
124 if(0.0 == fCompareValue
)
126 if(::basegfx::fTools::equalZero(mnX
))
131 if(::basegfx::fTools::equalZero(mnY
))
136 if(::basegfx::fTools::equalZero(mnZ
))
143 if(::basegfx::fTools::equal(mnX
, fCompareValue
))
148 if(::basegfx::fTools::equal(mnY
, fCompareValue
))
153 if(::basegfx::fTools::equal(mnZ
, fCompareValue
))
160 static const B3DTuple
& getEmptyTuple();
163 // external operators
166 inline B3DTuple
interpolate(const B3DTuple
& rOld1
, const B3DTuple
& rOld2
, double t
)
183 ((rOld2
.getX() - rOld1
.getX()) * t
) + rOld1
.getX(),
184 ((rOld2
.getY() - rOld1
.getY()) * t
) + rOld1
.getY(),
185 ((rOld2
.getZ() - rOld1
.getZ()) * t
) + rOld1
.getZ());
189 inline B3DTuple
average(const B3DTuple
& rOld1
, const B3DTuple
& rOld2
)
192 rtl_math_approxEqual(rOld1
.getX(), rOld2
.getX()) ? rOld1
.getX() : (rOld1
.getX() + rOld2
.getX()) * 0.5,
193 rtl_math_approxEqual(rOld1
.getY(), rOld2
.getY()) ? rOld1
.getY() : (rOld1
.getY() + rOld2
.getY()) * 0.5,
194 rtl_math_approxEqual(rOld1
.getZ(), rOld2
.getZ()) ? rOld1
.getZ() : (rOld1
.getZ() + rOld2
.getZ()) * 0.5);
197 inline B3DTuple
operator+(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
199 B3DTuple
aSum(rTupA
);
204 inline B3DTuple
operator-(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
206 B3DTuple
aSub(rTupA
);
211 inline B3DTuple
operator*(const B3DTuple
& rTupA
, const B3DTuple
& rTupB
)
213 B3DTuple
aMul(rTupA
);
218 inline B3DTuple
operator*(const B3DTuple
& rTup
, double t
)
225 inline B3DTuple
operator/(const B3DTuple
& rTup
, double t
)
232 /** Round double to nearest integer for 3D tuple
234 @return the nearest integer for this tuple
236 BASEGFX_DLLPUBLIC B3ITuple
fround(const B3DTuple
& rTup
);
237 } // end of namespace basegfx
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */