summaryrefslogtreecommitdiff
path: root/include/basegfx/tuple/Tuple3D.hxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-05-12 19:00:32 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-17 01:55:56 +0200
commitc703b2d22c3f45825d9c9d790c3b5a4b6f97e776 (patch)
tree74736ac1b3cc558c2fa37c028a6d8180bc749180 /include/basegfx/tuple/Tuple3D.hxx
parente337b9d92c6d5184e160df66885f53ebc4835218 (diff)
basegfx: generalise tuples with template class Tuple2D and Tuple3D
B2DTuple2D, B2ITuple2D and B2I64Tuple share a lot in common so we can generalise it as a template class. The same goes for the 3D variants - B3DTuple and B3ITuple. This is the initial attempt, but doesn't yet generalise all that is possible. Add some tests for the tuple variants that test the behaviour of overloaded operators and other common methods. Change-Id: Iee5ed15d58ea88e65ee7854bd05a87ceab22023d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117104 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/basegfx/tuple/Tuple3D.hxx')
-rw-r--r--include/basegfx/tuple/Tuple3D.hxx139
1 files changed, 139 insertions, 0 deletions
diff --git a/include/basegfx/tuple/Tuple3D.hxx b/include/basegfx/tuple/Tuple3D.hxx
new file mode 100644
index 000000000000..8ddcec8c618b
--- /dev/null
+++ b/include/basegfx/tuple/Tuple3D.hxx
@@ -0,0 +1,139 @@
+/* -*- 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 <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#include <basegfx/utils/common.hxx>
+#include <basegfx/numeric/ftools.hxx>
+
+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: */