summaryrefslogtreecommitdiffstats
path: root/include/basegfx/tuple
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /include/basegfx/tuple
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/basegfx/tuple')
-rw-r--r--include/basegfx/tuple/Size2D.hxx117
-rw-r--r--include/basegfx/tuple/Tuple2D.hxx180
-rw-r--r--include/basegfx/tuple/Tuple3D.hxx122
-rw-r--r--include/basegfx/tuple/b2dtuple.hxx153
-rw-r--r--include/basegfx/tuple/b2i64tuple.hxx87
-rw-r--r--include/basegfx/tuple/b2ituple.hxx95
-rw-r--r--include/basegfx/tuple/b3dtuple.hxx239
-rw-r--r--include/basegfx/tuple/b3ituple.hxx93
8 files changed, 1086 insertions, 0 deletions
diff --git a/include/basegfx/tuple/Size2D.hxx b/include/basegfx/tuple/Size2D.hxx
new file mode 100644
index 0000000000..28b967636f
--- /dev/null
+++ b/include/basegfx/tuple/Size2D.hxx
@@ -0,0 +1,117 @@
+/* -*- 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/tuple/Tuple2D.hxx>
+
+namespace basegfx
+{
+template <typename TYPE> class Size2D : protected Tuple2D<TYPE>
+{
+public:
+ Size2D(TYPE width, TYPE height)
+ : Tuple2D<TYPE>(width, height)
+ {
+ }
+
+ Size2D(Tuple2D<TYPE> const& rTuple)
+ : Tuple2D<TYPE>(rTuple.getX(), rTuple.getY())
+ {
+ }
+
+ TYPE getWidth() const { return Tuple2D<TYPE>::getX(); }
+
+ TYPE getHeight() const { return Tuple2D<TYPE>::getY(); }
+
+ void setWidth(TYPE const& rWidth) { Tuple2D<TYPE>::setX(rWidth); }
+
+ void setHeight(TYPE const& rHeight) { Tuple2D<TYPE>::setY(rHeight); }
+
+ bool operator==(Size2D<TYPE> const& rSize) const { return Tuple2D<TYPE>::operator==(rSize); }
+
+ bool operator!=(Size2D<TYPE> const& rSize) const { return Tuple2D<TYPE>::operator!=(rSize); }
+
+ Size2D<TYPE>& operator-=(Size2D<TYPE> const& rSize)
+ {
+ Tuple2D<TYPE>::operator-=(rSize);
+ return *this;
+ }
+
+ Size2D<TYPE>& operator+=(Size2D<TYPE> const& rSize)
+ {
+ Tuple2D<TYPE>::operator+=(rSize);
+ return *this;
+ }
+
+ Size2D<TYPE>& operator/=(Size2D<TYPE> const& rSize)
+ {
+ Tuple2D<TYPE>::operator/=(rSize);
+ return *this;
+ }
+
+ Size2D<TYPE>& operator*=(Size2D<TYPE> const& rSize)
+ {
+ Tuple2D<TYPE>::operator*=(rSize);
+ return *this;
+ }
+
+ Size2D<TYPE>& operator*=(TYPE value)
+ {
+ Tuple2D<TYPE>::operator*=(value);
+ return *this;
+ }
+
+ Size2D<TYPE>& operator/=(TYPE value)
+ {
+ Tuple2D<TYPE>::operator/=(value);
+ return *this;
+ }
+
+ Size2D<TYPE> operator-(void) const { return Tuple2D<TYPE>::operator-(); }
+
+ using Tuple2D<TYPE>::equalZero;
+};
+
+template <typename TYPE>
+inline Size2D<TYPE> operator-(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB)
+{
+ Size2D<TYPE> aNew(rSizeA);
+ aNew -= rSizeB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Size2D<TYPE> operator+(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB)
+{
+ Size2D<TYPE> aNew(rSizeA);
+ aNew += rSizeB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Size2D<TYPE> operator*(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB)
+{
+ Size2D<TYPE> aNew(rSizeA);
+ aNew *= rSizeB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Size2D<TYPE> operator/(const Size2D<TYPE>& rSizeA, const Size2D<TYPE>& rSizeB)
+{
+ Size2D<TYPE> aNew(rSizeA);
+ aNew /= rSizeB;
+ return aNew;
+}
+
+} // end of namespace gfx
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/tuple/Tuple2D.hxx b/include/basegfx/tuple/Tuple2D.hxx
new file mode 100644
index 0000000000..7494b4d1b1
--- /dev/null
+++ b/include/basegfx/tuple/Tuple2D.hxx
@@ -0,0 +1,180 @@
+/* -*- 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:
+ TYPE mnX;
+ TYPE mnY;
+
+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 mnX == rTup.mnX && mnY == rTup.mnY;
+ }
+
+ 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(mnX, rTup.mnX) && fTools::equal(mnY, rTup.mnY));
+ }
+
+ 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(mnX) && fTools::equalZero(mnY);
+ }
+
+ // operator overrides
+
+ Tuple2D<TYPE>& operator+=(const Tuple2D<TYPE>& rTup)
+ {
+ mnX += rTup.mnX;
+ mnY += rTup.mnY;
+ return *this;
+ }
+
+ Tuple2D<TYPE>& operator-=(const Tuple2D<TYPE>& rTup)
+ {
+ mnX -= rTup.mnX;
+ mnY -= rTup.mnY;
+ return *this;
+ }
+
+ Tuple2D<TYPE>& operator/=(const Tuple2D<TYPE>& rTup)
+ {
+ mnX /= rTup.mnX;
+ mnY /= rTup.mnY;
+ return *this;
+ }
+
+ Tuple2D<TYPE>& operator*=(const Tuple2D<TYPE>& rTup)
+ {
+ mnX *= rTup.mnX;
+ mnY *= rTup.mnY;
+ return *this;
+ }
+
+ Tuple2D<TYPE>& operator*=(TYPE t)
+ {
+ mnX *= t;
+ mnY *= t;
+ return *this;
+ }
+
+ Tuple2D<TYPE>& operator/=(TYPE t)
+ {
+ mnX /= t;
+ mnY /= t;
+ return *this;
+ }
+
+ Tuple2D<TYPE> operator-(void) const { return Tuple2D<TYPE>(-mnX, -mnY); }
+
+ bool operator==(const Tuple2D<TYPE>& rTup) const { return mnX == rTup.mnX && mnY == rTup.mnY; }
+
+ bool operator!=(const Tuple2D<TYPE>& rTup) const { return !(*this == rTup); }
+};
+
+template <typename TYPE>
+inline Tuple2D<TYPE> operator-(const Tuple2D<TYPE>& rTupA, const Tuple2D<TYPE>& rTupB)
+{
+ Tuple2D<TYPE> aNew(rTupA);
+ aNew -= rTupB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Tuple2D<TYPE> operator+(const Tuple2D<TYPE>& rTupA, const Tuple2D<TYPE>& rTupB)
+{
+ Tuple2D<TYPE> aNew(rTupA);
+ aNew += rTupB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Tuple2D<TYPE> operator*(const Tuple2D<TYPE>& rTupA, const Tuple2D<TYPE>& rTupB)
+{
+ Tuple2D<TYPE> aNew(rTupA);
+ aNew *= rTupB;
+ return aNew;
+}
+
+template <typename TYPE>
+inline Tuple2D<TYPE> operator/(const Tuple2D<TYPE>& rTupA, const Tuple2D<TYPE>& rTupB)
+{
+ Tuple2D<TYPE> aNew(rTupA);
+ aNew /= rTupB;
+ return aNew;
+}
+
+} // 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 0000000000..0b528c8341
--- /dev/null
+++ b/include/basegfx/tuple/Tuple3D.hxx
@@ -0,0 +1,122 @@
+/* -*- 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:
+ TYPE mnX;
+ TYPE mnY;
+ TYPE mnZ;
+
+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)
+ {
+ mnX += rTup.mnX;
+ mnY += rTup.mnY;
+ mnZ += rTup.mnZ;
+ return *this;
+ }
+
+ Tuple3D& operator-=(const Tuple3D& rTup)
+ {
+ mnX -= rTup.mnX;
+ mnY -= rTup.mnY;
+ mnZ -= rTup.mnZ;
+ return *this;
+ }
+
+ Tuple3D& operator/=(const Tuple3D& rTup)
+ {
+ mnX /= rTup.mnX;
+ mnY /= rTup.mnY;
+ mnZ /= rTup.mnZ;
+ return *this;
+ }
+
+ Tuple3D& operator*=(const Tuple3D& rTup)
+ {
+ mnX *= rTup.mnX;
+ mnY *= rTup.mnY;
+ mnZ *= rTup.mnZ;
+ return *this;
+ }
+
+ Tuple3D& operator*=(TYPE t)
+ {
+ mnX *= t;
+ mnY *= t;
+ mnZ *= t;
+ return *this;
+ }
+
+ Tuple3D& operator/=(TYPE t)
+ {
+ mnX /= t;
+ mnY /= t;
+ mnZ /= t;
+ return *this;
+ }
+
+ bool operator==(const Tuple3D& rTup) const
+ {
+ return mnX == rTup.mnX && mnY == rTup.mnY && mnZ == rTup.mnZ;
+ }
+
+ 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 0000000000..a4558f0d34
--- /dev/null
+++ b/include/basegfx/tuple/b2dtuple.hxx
@@ -0,0 +1,153 @@
+/* -*- 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)
+ {}
+
+ B2DTuple(Tuple2D<double> const& rTuple)
+ : Tuple2D(rTuple)
+ {}
+
+ /** 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(-mnX, -mnY);
+ }
+
+ 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& 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 0000000000..70838572f3
--- /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 0000000000..e3f195596a
--- /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 0000000000..2701b2f25c
--- /dev/null
+++ b/include/basegfx/tuple/b3dtuple.hxx
@@ -0,0 +1,239 @@
+/* -*- 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 mnX; if(1 == nPos) return mnY; return mnZ;
+ return *((&mnX) + 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 mnX; if(1 == nPos) return mnY; return mnZ;
+ return *((&mnX) + nPos);
+ }
+
+ // comparators with tolerance
+
+
+ bool equalZero() const
+ {
+ return (this == &getEmptyTuple() ||
+ (::basegfx::fTools::equalZero(mnX)
+ && ::basegfx::fTools::equalZero(mnY)
+ && ::basegfx::fTools::equalZero(mnZ)));
+ }
+
+ bool equal(const B3DTuple& rTup) const
+ {
+ return (
+ this == &rTup ||
+ (::basegfx::fTools::equal(mnX, rTup.mnX) &&
+ ::basegfx::fTools::equal(mnY, rTup.mnY) &&
+ ::basegfx::fTools::equal(mnZ, rTup.mnZ)));
+ }
+
+ // operators
+
+ B3DTuple operator-(void) const
+ {
+ return B3DTuple(-mnX, -mnY, -mnZ);
+ }
+
+ bool operator==(const B3DTuple& rTup) const
+ {
+ return ::basegfx::fTools::equal(mnX, rTup.mnX) &&
+ ::basegfx::fTools::equal(mnY, rTup.mnY) &&
+ ::basegfx::fTools::equal(mnZ, rTup.mnZ);
+ }
+
+ bool operator!=(const B3DTuple& rTup) const { return !operator==(rTup); }
+
+ void correctValues(const double fCompareValue = 0.0)
+ {
+ if(0.0 == fCompareValue)
+ {
+ if(::basegfx::fTools::equalZero(mnX))
+ {
+ mnX = 0.0;
+ }
+
+ if(::basegfx::fTools::equalZero(mnY))
+ {
+ mnY = 0.0;
+ }
+
+ if(::basegfx::fTools::equalZero(mnZ))
+ {
+ mnZ = 0.0;
+ }
+ }
+ else
+ {
+ if(::basegfx::fTools::equal(mnX, fCompareValue))
+ {
+ mnX = fCompareValue;
+ }
+
+ if(::basegfx::fTools::equal(mnY, fCompareValue))
+ {
+ mnY = fCompareValue;
+ }
+
+ if(::basegfx::fTools::equal(mnZ, fCompareValue))
+ {
+ mnZ = 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 0000000000..72c9fa8140
--- /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: */