summaryrefslogtreecommitdiffstats
path: root/include/basegfx/tuple
diff options
context:
space:
mode:
Diffstat (limited to 'include/basegfx/tuple')
-rw-r--r--include/basegfx/tuple/Tuple2D.hxx157
-rw-r--r--include/basegfx/tuple/Tuple3D.hxx134
-rw-r--r--include/basegfx/tuple/b2dtuple.hxx177
-rw-r--r--include/basegfx/tuple/b2i64tuple.hxx87
-rw-r--r--include/basegfx/tuple/b2ituple.hxx95
-rw-r--r--include/basegfx/tuple/b3dtuple.hxx237
-rw-r--r--include/basegfx/tuple/b3ituple.hxx93
7 files changed, 980 insertions, 0 deletions
diff --git a/include/basegfx/tuple/Tuple2D.hxx b/include/basegfx/tuple/Tuple2D.hxx
new file mode 100644
index 000000000..44d546df6
--- /dev/null
+++ b/include/basegfx/tuple/Tuple2D.hxx
@@ -0,0 +1,157 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+#include <basegfx/utils/common.hxx>
+#include <basegfx/numeric/ftools.hxx>
+
+namespace basegfx
+{
+template <typename TYPE> class Tuple2D
+{
+protected:
+ union {
+ // temporary alias mnX with mfX and mnY with mfY
+ struct
+ {
+ TYPE mnX;
+ TYPE mnY;
+ };
+ struct
+ {
+ TYPE mfX;
+ TYPE mfY;
+ };
+ };
+
+public:
+ /** Create a 2D Tuple
+
+ @param nX
+ This parameter is used to initialize the X-coordinate
+ of the 2D Tuple.
+
+ @param nY
+ This parameter is used to initialize the Y-coordinate
+ of the 2D Tuple.
+ */
+ Tuple2D(TYPE x, TYPE y)
+ : mnX(x)
+ , mnY(y)
+ {
+ }
+
+ double get(Axis2D eAxis) { return eAxis == Axis2D::X ? getX() : getY(); }
+
+ void set(Axis2D eAxis, TYPE fValue)
+ {
+ if (eAxis == Axis2D::X)
+ setX(fValue);
+ else
+ setY(fValue);
+ }
+
+ /// Get X-Coordinate of 2D Tuple
+ TYPE getX() const { return mnX; }
+
+ /// Get Y-Coordinate of 2D Tuple
+ TYPE getY() const { return mnY; }
+
+ /// Set X-Coordinate of 2D Tuple
+ void setX(TYPE fX) { mnX = fX; }
+
+ /// Set Y-Coordinate of 2D Tuple
+ void setY(TYPE fY) { mnY = fY; }
+
+ /// Adjust X-Coordinate of 2D Tuple
+ void adjustX(TYPE fX) { mnX += fX; }
+
+ /// Adjust Y-Coordinate of 2D Tuple
+ void adjustY(TYPE fY) { mnY += fY; }
+
+ // comparators with tolerance
+
+ template <typename T = TYPE, std::enable_if_t<std::is_integral_v<T>, int> = 0>
+ bool equal(const Tuple2D<TYPE>& rTup) const
+ {
+ return mfX == rTup.mfX && mfY == rTup.mfY;
+ }
+
+ template <typename T = TYPE, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
+ bool equal(const Tuple2D<TYPE>& rTup) const
+ {
+ return this == &rTup || (fTools::equal(mfX, rTup.mfX) && fTools::equal(mfY, rTup.mfY));
+ }
+
+ template <typename T = TYPE, std::enable_if_t<std::is_integral_v<T>, int> = 0>
+ bool equalZero() const
+ {
+ return mnX == 0 && mnY == 0;
+ }
+
+ template <typename T = TYPE, std::enable_if_t<std::is_floating_point_v<T>, int> = 0>
+ bool equalZero() const
+ {
+ return fTools::equalZero(mfX) && fTools::equalZero(mfY);
+ }
+
+ // operator overrides
+
+ Tuple2D& operator+=(const Tuple2D& rTup)
+ {
+ mfX += rTup.mfX;
+ mfY += rTup.mfY;
+ return *this;
+ }
+
+ Tuple2D& operator-=(const Tuple2D& rTup)
+ {
+ mfX -= rTup.mfX;
+ mfY -= rTup.mfY;
+ return *this;
+ }
+
+ Tuple2D& operator/=(const Tuple2D& rTup)
+ {
+ mfX /= rTup.mfX;
+ mfY /= rTup.mfY;
+ return *this;
+ }
+
+ Tuple2D& operator*=(const Tuple2D& rTup)
+ {
+ mfX *= rTup.mfX;
+ mfY *= rTup.mfY;
+ return *this;
+ }
+
+ Tuple2D& operator*=(TYPE t)
+ {
+ mfX *= t;
+ mfY *= t;
+ return *this;
+ }
+
+ Tuple2D& operator/=(TYPE t)
+ {
+ mfX /= t;
+ mfY /= t;
+ return *this;
+ }
+
+ bool operator==(const Tuple2D& rTup) const { return mfX == rTup.mfX && mfY == rTup.mfY; }
+
+ bool operator!=(const Tuple2D& rTup) const { return !(*this == rTup); }
+};
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/Tuple3D.hxx b/include/basegfx/tuple/Tuple3D.hxx
new file mode 100644
index 000000000..967516663
--- /dev/null
+++ b/include/basegfx/tuple/Tuple3D.hxx
@@ -0,0 +1,134 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#pragma once
+
+namespace basegfx
+{
+template <typename TYPE> class Tuple3D
+{
+protected:
+ union {
+ // temporary alias mnX with mfX, mnY with mfY and mnZ with mfZ
+ struct
+ {
+ TYPE mnX;
+ TYPE mnY;
+ TYPE mnZ;
+ };
+ struct
+ {
+ TYPE mfX;
+ TYPE mfY;
+ TYPE mfZ;
+ };
+ };
+
+public:
+ /** Create a 3D Tuple
+
+ @param x
+ This parameter is used to initialize the X-coordinate
+ of the 3D Tuple.
+
+ @param y
+ This parameter is used to initialize the Y-coordinate
+ of the 3D Tuple.
+
+ @param z
+ This parameter is used to initialize the Z-coordinate
+ of the 3D Tuple.
+ */
+ Tuple3D(TYPE x, TYPE y, TYPE z)
+ : mnX(x)
+ , mnY(y)
+ , mnZ(z)
+ {
+ }
+
+ /// Get X-Coordinate of 3D Tuple
+ TYPE getX() const { return mnX; }
+
+ /// Get Y-Coordinate of 3D Tuple
+ TYPE getY() const { return mnY; }
+
+ /// Get Z-Coordinate of 3D Tuple
+ TYPE getZ() const { return mnZ; }
+
+ /// Set X-Coordinate of 3D Tuple
+ void setX(TYPE fX) { mnX = fX; }
+
+ /// Set Y-Coordinate of 3D Tuple
+ void setY(TYPE fY) { mnY = fY; }
+
+ /// Set Z-Coordinate of 3D Tuple
+ void setZ(TYPE fZ) { mnZ = fZ; }
+
+ // operators
+
+ Tuple3D& operator+=(const Tuple3D& rTup)
+ {
+ mfX += rTup.mfX;
+ mfY += rTup.mfY;
+ mfZ += rTup.mfZ;
+ return *this;
+ }
+
+ Tuple3D& operator-=(const Tuple3D& rTup)
+ {
+ mfX -= rTup.mfX;
+ mfY -= rTup.mfY;
+ mfZ -= rTup.mfZ;
+ return *this;
+ }
+
+ Tuple3D& operator/=(const Tuple3D& rTup)
+ {
+ mfX /= rTup.mfX;
+ mfY /= rTup.mfY;
+ mfZ /= rTup.mfZ;
+ return *this;
+ }
+
+ Tuple3D& operator*=(const Tuple3D& rTup)
+ {
+ mfX *= rTup.mfX;
+ mfY *= rTup.mfY;
+ mfZ *= rTup.mfZ;
+ return *this;
+ }
+
+ Tuple3D& operator*=(TYPE t)
+ {
+ mfX *= t;
+ mfY *= t;
+ mfZ *= t;
+ return *this;
+ }
+
+ Tuple3D& operator/=(TYPE t)
+ {
+ mfX /= t;
+ mfY /= t;
+ mfZ /= t;
+ return *this;
+ }
+
+ bool operator==(const Tuple3D& rTup) const
+ {
+ return mfX == rTup.mfX && mfY == rTup.mfY && mfZ == rTup.mfZ;
+ }
+
+ bool operator!=(const Tuple3D& rTup) const { return !operator==(rTup); }
+};
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/b2dtuple.hxx b/include/basegfx/tuple/b2dtuple.hxx
new file mode 100644
index 000000000..c47b7b898
--- /dev/null
+++ b/include/basegfx/tuple/b2dtuple.hxx
@@ -0,0 +1,177 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple2D.hxx>
+
+namespace basegfx
+{
+ class B2ITuple;
+
+ /** Base class for all Points/Vectors with two double values
+
+ This class provides all methods common to Point
+ and Vector classes which are derived from here.
+
+ @derive Use this class to implement Points or Vectors
+ which are based on two double values
+ */
+ class SAL_WARN_UNUSED B2DTuple : public Tuple2D<double>
+ {
+ public:
+
+ /** Create a 2D Tuple
+
+ The tuple is initialized to (0.0, 0.0)
+ */
+ B2DTuple()
+ : Tuple2D(0.0, 0.0)
+ {}
+
+ /** Create a 2D Tuple
+
+ @param fX
+ This parameter is used to initialize the X-coordinate
+ of the 2D Tuple.
+
+ @param fY
+ This parameter is used to initialize the Y-coordinate
+ of the 2D Tuple.
+ */
+ B2DTuple(double fX, double fY)
+ : Tuple2D(fX, fY)
+ {}
+
+ /** Create a copy of a 2D integer Tuple
+
+ @param rTup
+ The 2D Tuple which will be copied.
+ */
+ BASEGFX_DLLPUBLIC explicit B2DTuple(const B2ITuple& rTup);
+
+ // operators
+
+ B2DTuple operator-(void) const
+ {
+ return B2DTuple(-mfX, -mfY);
+ }
+
+ BASEGFX_DLLPUBLIC static const B2DTuple& getEmptyTuple();
+ };
+
+ // external operators
+
+
+ inline B2DTuple absolute(const B2DTuple& rTup)
+ {
+ B2DTuple aAbs(
+ fabs(rTup.getX()),
+ fabs(rTup.getY()));
+ return aAbs;
+ }
+
+ inline B2DTuple interpolate(const B2DTuple& rOld1, const B2DTuple& rOld2, double t)
+ {
+ if(rOld1 == rOld2)
+ {
+ return rOld1;
+ }
+ else if(0.0 >= t)
+ {
+ return rOld1;
+ }
+ else if(1.0 <= t)
+ {
+ return rOld2;
+ }
+ else
+ {
+ return B2DTuple(
+ ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
+ ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY());
+ }
+ }
+
+ inline B2DTuple average(const B2DTuple& rOld1, const B2DTuple& rOld2)
+ {
+ return B2DTuple(
+ rtl_math_approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
+ rtl_math_approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5);
+ }
+
+ inline B2DTuple operator+(const B2DTuple& rTupA, const B2DTuple& rTupB)
+ {
+ B2DTuple aSum(rTupA);
+ aSum += rTupB;
+ return aSum;
+ }
+
+ inline B2DTuple operator-(const B2DTuple& rTupA, const B2DTuple& rTupB)
+ {
+ B2DTuple aSub(rTupA);
+ aSub -= rTupB;
+ return aSub;
+ }
+
+ inline B2DTuple operator/(const B2DTuple& rTupA, const B2DTuple& rTupB)
+ {
+ B2DTuple aDiv(rTupA);
+ aDiv /= rTupB;
+ return aDiv;
+ }
+
+ inline B2DTuple operator*(const B2DTuple& rTupA, const B2DTuple& rTupB)
+ {
+ B2DTuple aMul(rTupA);
+ aMul *= rTupB;
+ return aMul;
+ }
+
+ inline B2DTuple operator*(const B2DTuple& rTup, double t)
+ {
+ B2DTuple aNew(rTup);
+ aNew *= t;
+ return aNew;
+ }
+
+ inline B2DTuple operator*(double t, const B2DTuple& rTup)
+ {
+ B2DTuple aNew(rTup);
+ aNew *= t;
+ return aNew;
+ }
+
+ inline B2DTuple operator/(const B2DTuple& rTup, double t)
+ {
+ B2DTuple aNew(rTup);
+ aNew /= t;
+ return aNew;
+ }
+
+ /** Round double to nearest integer for 2D tuple
+
+ @return the nearest integer for this tuple
+ */
+ BASEGFX_DLLPUBLIC B2ITuple fround(const B2DTuple& rTup);
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/b2i64tuple.hxx b/include/basegfx/tuple/b2i64tuple.hxx
new file mode 100644
index 000000000..70838572f
--- /dev/null
+++ b/include/basegfx/tuple/b2i64tuple.hxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple2D.hxx>
+
+namespace basegfx
+{
+ /** Base class for all Points/Vectors with two sal_Int64 values
+
+ This class provides all methods common to Point
+ and Vector classes which are derived from here.
+
+ @derive Use this class to implement Points or Vectors
+ which are based on two sal_Int64 values
+ */
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2I64Tuple : public Tuple2D<sal_Int64>
+ {
+ public:
+ /** Create a 2D Tuple
+
+ The tuple is initialized to (0, 0)
+ */
+ B2I64Tuple()
+ : Tuple2D(0, 0)
+ {}
+
+ /** Create a 2D Tuple
+
+ @param nX
+ This parameter is used to initialize the X-coordinate
+ of the 2D Tuple.
+
+ @param nY
+ This parameter is used to initialize the Y-coordinate
+ of the 2D Tuple.
+ */
+ B2I64Tuple(sal_Int64 nX, sal_Int64 nY)
+ : Tuple2D(nX, nY)
+ {}
+
+ /** Create a copy of a 2D Tuple
+
+ @param rTup
+ The 2D Tuple which will be copied.
+ */
+ B2I64Tuple(const B2I64Tuple& rTup)
+ : Tuple2D(rTup.mnX, rTup.mnY)
+ {}
+
+ // operators
+
+ B2I64Tuple operator-(void) const
+ {
+ return B2I64Tuple(-mnX, -mnY);
+ }
+
+ B2I64Tuple& operator=( const B2I64Tuple& rTup )
+ {
+ mnX = rTup.mnX;
+ mnY = rTup.mnY;
+ return *this;
+ }
+ };
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/b2ituple.hxx b/include/basegfx/tuple/b2ituple.hxx
new file mode 100644
index 000000000..e3f195596
--- /dev/null
+++ b/include/basegfx/tuple/b2ituple.hxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple2D.hxx>
+
+namespace basegfx
+{
+ /** Base class for all Points/Vectors with two sal_Int32 values
+
+ This class provides all methods common to Point
+ and Vector classes which are derived from here.
+
+ @derive Use this class to implement Points or Vectors
+ which are based on two sal_Int32 values
+ */
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple : public Tuple2D<sal_Int32>
+ {
+ public:
+ /** Create a 2D Tuple
+
+ The tuple is initialized to (0, 0)
+ */
+ B2ITuple()
+ : Tuple2D(0, 0)
+ {}
+
+ /** Create a 2D Tuple
+
+ @param nX
+ This parameter is used to initialize the X-coordinate
+ of the 2D Tuple.
+
+ @param nY
+ This parameter is used to initialize the Y-coordinate
+ of the 2D Tuple.
+ */
+ B2ITuple(sal_Int32 nX, sal_Int32 nY)
+ : Tuple2D(nX, nY)
+ {}
+
+ // operators
+
+ B2ITuple operator-(void) const
+ {
+ return B2ITuple(-mnX, -mnY);
+ }
+ };
+
+ // external operators
+
+
+ inline B2ITuple operator+(const B2ITuple& rTupA, const B2ITuple& rTupB)
+ {
+ B2ITuple aSum(rTupA);
+ aSum += rTupB;
+ return aSum;
+ }
+
+ inline B2ITuple operator-(const B2ITuple& rTupA, const B2ITuple& rTupB)
+ {
+ B2ITuple aSub(rTupA);
+ aSub -= rTupB;
+ return aSub;
+ }
+
+ inline B2ITuple operator*(sal_Int32 t, const B2ITuple& rTup)
+ {
+ B2ITuple aNew(rTup);
+ aNew *= t;
+ return aNew;
+ }
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/b3dtuple.hxx b/include/basegfx/tuple/b3dtuple.hxx
new file mode 100644
index 000000000..7ac6a774b
--- /dev/null
+++ b/include/basegfx/tuple/b3dtuple.hxx
@@ -0,0 +1,237 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <basegfx/numeric/ftools.hxx>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple3D.hxx>
+
+namespace basegfx
+{
+ class B3ITuple;
+
+ /** Base class for all Points/Vectors with three double values
+
+ This class provides all methods common to Point
+ and Vector classes which are derived from here.
+
+ @derive Use this class to implement Points or Vectors
+ which are based on three double values
+ */
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3DTuple : public Tuple3D<double>
+ {
+ public:
+ /** Create a 3D Tuple
+
+ The tuple is initialized to (0.0, 0.0, 0.0)
+ */
+ B3DTuple()
+ : Tuple3D(0.0, 0.0, 0.0)
+ {}
+
+ /** Create a 3D Tuple
+
+ @param fX
+ This parameter is used to initialize the X-coordinate
+ of the 3D Tuple.
+
+ @param fY
+ This parameter is used to initialize the Y-coordinate
+ of the 3D Tuple.
+
+ @param fZ
+ This parameter is used to initialize the Z-coordinate
+ of the 3D Tuple.
+ */
+ B3DTuple(double fX, double fY, double fZ)
+ : Tuple3D(fX, fY, fZ)
+ {}
+
+ /// Array-access to 3D Tuple
+ const double& operator[] (int nPos) const
+ {
+ // Here, normally two if(...)'s should be used. In the assumption that
+ // both double members can be accessed as an array a shortcut is used here.
+ // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
+ return *((&mfX) + nPos);
+ }
+
+ /// Array-access to 3D Tuple
+ double& operator[] (int nPos)
+ {
+ // Here, normally two if(...)'s should be used. In the assumption that
+ // both double members can be accessed as an array a shortcut is used here.
+ // if(0 == nPos) return mfX; if(1 == nPos) return mfY; return mfZ;
+ return *((&mfX) + nPos);
+ }
+
+ // comparators with tolerance
+
+
+ bool equalZero() const
+ {
+ return (this == &getEmptyTuple() ||
+ (::basegfx::fTools::equalZero(mfX)
+ && ::basegfx::fTools::equalZero(mfY)
+ && ::basegfx::fTools::equalZero(mfZ)));
+ }
+
+ bool equal(const B3DTuple& rTup) const
+ {
+ return (
+ this == &rTup ||
+ (::basegfx::fTools::equal(mfX, rTup.mfX) &&
+ ::basegfx::fTools::equal(mfY, rTup.mfY) &&
+ ::basegfx::fTools::equal(mfZ, rTup.mfZ)));
+ }
+
+ // operators
+
+ B3DTuple operator-(void) const
+ {
+ return B3DTuple(-mfX, -mfY, -mfZ);
+ }
+
+ bool operator==(const B3DTuple& rTup) const
+ {
+ return mfX == rTup.mfX && mfY == rTup.mfY && mfZ == rTup.mfZ;
+ }
+
+ bool operator!=(const B3DTuple& rTup) const { return !operator==(rTup); }
+
+ void correctValues(const double fCompareValue = 0.0)
+ {
+ if(0.0 == fCompareValue)
+ {
+ if(::basegfx::fTools::equalZero(mfX))
+ {
+ mfX = 0.0;
+ }
+
+ if(::basegfx::fTools::equalZero(mfY))
+ {
+ mfY = 0.0;
+ }
+
+ if(::basegfx::fTools::equalZero(mfZ))
+ {
+ mfZ = 0.0;
+ }
+ }
+ else
+ {
+ if(::basegfx::fTools::equal(mfX, fCompareValue))
+ {
+ mfX = fCompareValue;
+ }
+
+ if(::basegfx::fTools::equal(mfY, fCompareValue))
+ {
+ mfY = fCompareValue;
+ }
+
+ if(::basegfx::fTools::equal(mfZ, fCompareValue))
+ {
+ mfZ = fCompareValue;
+ }
+ }
+ }
+
+ static const B3DTuple& getEmptyTuple();
+ };
+
+ // external operators
+
+
+ inline B3DTuple interpolate(const B3DTuple& rOld1, const B3DTuple& rOld2, double t)
+ {
+ if(rOld1 == rOld2)
+ {
+ return rOld1;
+ }
+ else if(0.0 >= t)
+ {
+ return rOld1;
+ }
+ else if(1.0 <= t)
+ {
+ return rOld2;
+ }
+ else
+ {
+ return B3DTuple(
+ ((rOld2.getX() - rOld1.getX()) * t) + rOld1.getX(),
+ ((rOld2.getY() - rOld1.getY()) * t) + rOld1.getY(),
+ ((rOld2.getZ() - rOld1.getZ()) * t) + rOld1.getZ());
+ }
+ }
+
+ inline B3DTuple average(const B3DTuple& rOld1, const B3DTuple& rOld2)
+ {
+ return B3DTuple(
+ rtl_math_approxEqual(rOld1.getX(), rOld2.getX()) ? rOld1.getX() : (rOld1.getX() + rOld2.getX()) * 0.5,
+ rtl_math_approxEqual(rOld1.getY(), rOld2.getY()) ? rOld1.getY() : (rOld1.getY() + rOld2.getY()) * 0.5,
+ rtl_math_approxEqual(rOld1.getZ(), rOld2.getZ()) ? rOld1.getZ() : (rOld1.getZ() + rOld2.getZ()) * 0.5);
+ }
+
+ inline B3DTuple operator+(const B3DTuple& rTupA, const B3DTuple& rTupB)
+ {
+ B3DTuple aSum(rTupA);
+ aSum += rTupB;
+ return aSum;
+ }
+
+ inline B3DTuple operator-(const B3DTuple& rTupA, const B3DTuple& rTupB)
+ {
+ B3DTuple aSub(rTupA);
+ aSub -= rTupB;
+ return aSub;
+ }
+
+ inline B3DTuple operator*(const B3DTuple& rTupA, const B3DTuple& rTupB)
+ {
+ B3DTuple aMul(rTupA);
+ aMul *= rTupB;
+ return aMul;
+ }
+
+ inline B3DTuple operator*(const B3DTuple& rTup, double t)
+ {
+ B3DTuple aNew(rTup);
+ aNew *= t;
+ return aNew;
+ }
+
+ inline B3DTuple operator/(const B3DTuple& rTup, double t)
+ {
+ B3DTuple aNew(rTup);
+ aNew /= t;
+ return aNew;
+ }
+
+ /** Round double to nearest integer for 3D tuple
+
+ @return the nearest integer for this tuple
+ */
+ BASEGFX_DLLPUBLIC B3ITuple fround(const B3DTuple& rTup);
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/b3ituple.hxx b/include/basegfx/tuple/b3ituple.hxx
new file mode 100644
index 000000000..72c9fa814
--- /dev/null
+++ b/include/basegfx/tuple/b3ituple.hxx
@@ -0,0 +1,93 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple3D.hxx>
+
+namespace basegfx
+{
+ /** Base class for all Points/Vectors with three sal_Int32 values
+
+ This class provides all methods common to Point
+ and Vector classes which are derived from here.
+
+ @derive Use this class to implement Points or Vectors
+ which are based on three sal_Int32 values
+ */
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3ITuple : public Tuple3D<sal_Int32>
+ {
+ public:
+ /** Create a 3D Tuple
+
+ The tuple is initialized to (0, 0, 0)
+ */
+ B3ITuple()
+ : Tuple3D(0, 0, 0)
+ {}
+
+ /** Create a 3D Tuple
+
+ @param nX
+ This parameter is used to initialize the X-coordinate
+ of the 3D Tuple.
+
+ @param nY
+ This parameter is used to initialize the Y-coordinate
+ of the 3D Tuple.
+
+ @param nZ
+ This parameter is used to initialize the Z-coordinate
+ of the 3D Tuple.
+ */
+ B3ITuple(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ)
+ : Tuple3D(nX, nY, nZ)
+ {}
+
+ /// Array-access to 3D Tuple
+ const sal_Int32& operator[] (int nPos) const
+ {
+ // Here, normally two if(...)'s should be used. In the assumption that
+ // both sal_Int32 members can be accessed as an array a shortcut is used here.
+ // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
+ return *((&mnX) + nPos);
+ }
+
+ /// Array-access to 3D Tuple
+ sal_Int32& operator[] (int nPos)
+ {
+ // Here, normally two if(...)'s should be used. In the assumption that
+ // both sal_Int32 members can be accessed as an array a shortcut is used here.
+ // if(0 == nPos) return mnX; if(1 == nPos) return mnY; return mnZ;
+ return *((&mnX) + nPos);
+ }
+
+ // operators
+
+ B3ITuple operator-(void) const
+ {
+ return B3ITuple(-mnX, -mnY, -mnZ);
+ }
+ };
+
+} // end of namespace basegfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */