summaryrefslogtreecommitdiff
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
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>
-rw-r--r--basegfx/CppunitTest_basegfx.mk1
-rw-r--r--basegfx/source/tuple/b2dtuple.cxx3
-rw-r--r--basegfx/test/B2DTupleTest.cxx204
-rw-r--r--basegfx/test/B3DTupleTest.cxx194
-rw-r--r--include/basegfx/tuple/Tuple2D.hxx157
-rw-r--r--include/basegfx/tuple/Tuple3D.hxx139
-rw-r--r--include/basegfx/tuple/b2dtuple.hxx121
-rw-r--r--include/basegfx/tuple/b2i64tuple.hxx105
-rw-r--r--include/basegfx/tuple/b2ituple.hxx119
-rw-r--r--include/basegfx/tuple/b3dtuple.hxx109
-rw-r--r--include/basegfx/tuple/b3ituple.hxx87
11 files changed, 714 insertions, 525 deletions
diff --git a/basegfx/CppunitTest_basegfx.mk b/basegfx/CppunitTest_basegfx.mk
index a0379e76612a..310424bd6446 100644
--- a/basegfx/CppunitTest_basegfx.mk
+++ b/basegfx/CppunitTest_basegfx.mk
@@ -34,6 +34,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,basegfx,\
basegfx/test/B2XRangeTest \
basegfx/test/B2IBoxTest \
basegfx/test/B2DTupleTest \
+ basegfx/test/B3DTupleTest \
basegfx/test/BColorModifierTest \
basegfx/test/BColorTest \
basegfx/test/SvgPathImportExport \
diff --git a/basegfx/source/tuple/b2dtuple.cxx b/basegfx/source/tuple/b2dtuple.cxx
index c894639a1511..18a93f8d731c 100644
--- a/basegfx/source/tuple/b2dtuple.cxx
+++ b/basegfx/source/tuple/b2dtuple.cxx
@@ -30,8 +30,7 @@ namespace basegfx
}
B2DTuple::B2DTuple(const B2ITuple& rTup)
- : mfX( rTup.getX() ),
- mfY( rTup.getY() )
+ : Tuple2D(rTup.getX(), rTup.getY())
{}
B2ITuple fround(const B2DTuple& rTup)
diff --git a/basegfx/test/B2DTupleTest.cxx b/basegfx/test/B2DTupleTest.cxx
index b2ffd28e84f3..100808fe8a78 100644
--- a/basegfx/test/B2DTupleTest.cxx
+++ b/basegfx/test/B2DTupleTest.cxx
@@ -20,29 +20,211 @@
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
+#include <basegfx/tuple/b2dtuple.hxx>
+#include <basegfx/tuple/b2ituple.hxx>
+#include <basegfx/tuple/b2i64tuple.hxx>
+
namespace basegfx
{
-class b2dtuple : public CppUnit::TestFixture
+class B2DTupleTest : public CppUnit::TestFixture
{
public:
- // insert your test code here.
- // this is only demonstration code
- void EmptyMethod()
+ void testEmpty()
+ {
+ B2DTuple aTuple;
+ CPPUNIT_ASSERT_EQUAL(true, aTuple.equalZero());
+
+ B2ITuple aTupleInteger;
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInteger.equalZero());
+
+ B2I64Tuple aTupleLong;
+ CPPUNIT_ASSERT_EQUAL(true, aTupleLong.equalZero());
+ }
+
+ void testEquals()
+ {
+ B2DTuple aTuple(1.0, 1.0);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple.equal({ 1.0, 1.0 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple.equal({ 0.99, 0.99 }));
+
+ B2ITuple aTupleInteger(1, 1);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInteger.equal({ 1, 1 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInteger.equal({ 1, 0 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInteger.equal({ 0, 1 }));
+
+ B2I64Tuple aTupleLong(1, 1);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleLong.equal({ 1, 1 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleLong.equal({ 1, 0 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleLong.equal({ 0, 1 }));
+ }
+
+ void testOperatorAddition()
+ {
+ B2DTuple aTuple(4.0, 8.0);
+ aTuple += { 2.0, 3.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, aTuple.getY(), 1e-2);
+
+ B2ITuple aTupleInt(4, 8);
+ aTupleInt += { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aTupleInt.getY());
+
+ B2I64Tuple aTuple64(4, 8);
+ aTuple64 += { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(6), aTuple64.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(11), aTuple64.getY());
+ }
+
+ void testOperatorSubstraction()
+ {
+ B2DTuple aTuple(4.0, 8.0);
+ aTuple -= { 2.0, 3.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aTuple.getY(), 1e-2);
+
+ B2ITuple aTupleInt(4, 8);
+ aTupleInt -= { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aTupleInt.getY());
+
+ B2I64Tuple aTuple64(4, 8);
+ aTuple64 -= { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(2), aTuple64.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(5), aTuple64.getY());
+ }
+
+ void testOperatorMultiply()
+ {
+ B2DTuple aTuple(4.0, 8.0);
+ aTuple *= { 2.0, 3.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(24.0, aTuple.getY(), 1e-2);
+
+ aTuple *= 2.0;
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, aTuple.getY(), 1e-2);
+
+ B2ITuple aTupleInt(4, 8);
+ aTupleInt *= { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(24), aTupleInt.getY());
+
+ aTupleInt *= 2.0;
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(48), aTupleInt.getY());
+
+ B2I64Tuple aTuple64(4, 8);
+ aTuple64 *= { 2, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(8), aTuple64.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(24), aTuple64.getY());
+
+ aTuple64 *= 2.0;
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(16), aTuple64.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(48), aTuple64.getY());
+ }
+
+ void testOperatorDivide()
{
- // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
+ B2DTuple aTuple(4.0, 8.0);
+ aTuple /= { 2.0, 8.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aTuple.getY(), 1e-2);
+
+ B2ITuple aTupleInt(4, 8);
+ aTupleInt /= { 2, 8 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aTupleInt.getY());
+
+ B2I64Tuple aTuple64(4, 8);
+ aTuple64 /= { 2, 8 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(2), aTuple64.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(1), aTuple64.getY());
+ }
+
+ void testOperatorEqualUnequal()
+ {
+ B2DTuple aTuple(4.0, 8.0);
+ B2DTuple aTuple2 = aTuple;
+
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == aTuple);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == aTuple2);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == B2DTuple(4.0, 8.0));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple == B2DTuple(4.0, 7.99));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple == B2DTuple(3.99, 8.0));
+
+ B2ITuple aTupleInt(4, 8);
+ B2ITuple aTupleInt2 = aTupleInt;
+
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == aTupleInt);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == aTupleInt2);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == B2ITuple(4, 8));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt == B2ITuple(4, 7));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt == B2ITuple(3, 8));
+
+ B2I64Tuple aTuple64(4, 8);
+ B2I64Tuple aTuple64_2 = aTuple64;
+
+ CPPUNIT_ASSERT_EQUAL(true, aTuple64 == aTuple64);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple64 == aTuple64_2);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple64 == B2I64Tuple(4, 8));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple64 == B2I64Tuple(4, 7));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple64 == B2I64Tuple(3, 8));
}
- // Change the following lines only, if you add, remove or rename
- // member functions of the current class,
- // because these macros are need by auto register mechanism.
+ void testOperatorMinus()
+ {
+ B2DTuple aTupleMinus = -B2DTuple(4.0, 8.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.0, aTupleMinus.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.0, aTupleMinus.getY(), 1e-2);
+ B2DTuple aTupleZero = -B2DTuple(0.0, 0.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero.getY(), 1e-2);
+
+ B2ITuple aTupleIntMinus = -B2ITuple(4, 8);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-4), aTupleIntMinus.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-8), aTupleIntMinus.getY());
+ B2ITuple aTupleIntZero = -B2ITuple(0, 0);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero.getY());
+
+ B2I64Tuple aTuple64Minus = -B2I64Tuple(4, 8);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(-4), aTuple64Minus.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(-8), aTuple64Minus.getY());
+ B2I64Tuple aTuple64Zero = -B2I64Tuple(0, 0);
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(0), aTuple64Zero.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int64(0), aTuple64Zero.getY());
+ }
- CPPUNIT_TEST_SUITE(b2dtuple);
- CPPUNIT_TEST(EmptyMethod);
+ CPPUNIT_TEST_SUITE(B2DTupleTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testEquals);
+ CPPUNIT_TEST(testOperatorAddition);
+ CPPUNIT_TEST(testOperatorSubstraction);
+ CPPUNIT_TEST(testOperatorMultiply);
+ CPPUNIT_TEST(testOperatorDivide);
+ CPPUNIT_TEST(testOperatorEqualUnequal);
+ CPPUNIT_TEST(testOperatorMinus);
CPPUNIT_TEST_SUITE_END();
};
} // namespace basegfx
-CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::b2dtuple);
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B2DTupleTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/test/B3DTupleTest.cxx b/basegfx/test/B3DTupleTest.cxx
new file mode 100644
index 000000000000..cb8607ea9774
--- /dev/null
+++ b/basegfx/test/B3DTupleTest.cxx
@@ -0,0 +1,194 @@
+/* -*- 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 .
+ */
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <basegfx/tuple/b3dtuple.hxx>
+#include <basegfx/tuple/b3ituple.hxx>
+
+namespace basegfx
+{
+class B3DTupleTest : public CppUnit::TestFixture
+{
+public:
+ void testEmpty()
+ {
+ B3DTuple aTuple;
+ CPPUNIT_ASSERT_EQUAL(true, aTuple.equalZero());
+ }
+
+ void testEquals()
+ {
+ B3DTuple aTuple(1.0, 1.0, 1.0);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple.equal({ 1.0, 1.0, 1.0 }));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple.equal({ 0.99, 0.99, 0.99 }));
+ }
+
+ void testOperatorAddition()
+ {
+ B3DTuple aTuple(4.0, 8.0, 1.0);
+ aTuple += { 2.0, 3.0, 4.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(6.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(11.0, aTuple.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aTuple.getZ(), 1e-2);
+
+ B3ITuple aTupleInt(4, 8, 1);
+ aTupleInt += { 2, 3, 4 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(6), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11), aTupleInt.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aTupleInt.getZ());
+ }
+
+ void testOperatorSubstraction()
+ {
+ B3DTuple aTuple(4.0, 8.0, 1.0);
+ aTuple -= { 2.0, 3.0, 4.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, aTuple.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-3.0, aTuple.getZ(), 1e-2);
+
+ B3ITuple aTupleInt(4, 8, 1);
+ aTupleInt -= { 2, 3, 4 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(5), aTupleInt.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-3), aTupleInt.getZ());
+ }
+
+ void testOperatorMultiply()
+ {
+ B3DTuple aTuple(4.0, 8.0, 1.0);
+ aTuple *= { 2.0, 3.0, 4.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(24.0, aTuple.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(4.0, aTuple.getZ(), 1e-2);
+
+ aTuple *= 2.0;
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(16.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(48.0, aTuple.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(8.0, aTuple.getZ(), 1e-2);
+
+ B3ITuple aTupleInt(4, 8, 1);
+ aTupleInt *= { 2, 3, 4 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(24), aTupleInt.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), aTupleInt.getZ());
+
+ aTupleInt *= 2.0;
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(16), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(48), aTupleInt.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(8), aTupleInt.getZ());
+ }
+
+ void testOperatorDivide()
+ {
+ B3DTuple aTuple(4.0, 8.0, 9.0);
+ aTuple /= { 2.0, 8.0, 3.0 };
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(2.0, aTuple.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, aTuple.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(3.0, aTuple.getZ(), 1e-2);
+
+ B3ITuple aTupleInt(4, 8, 9);
+ aTupleInt /= { 2, 8, 3 };
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aTupleInt.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aTupleInt.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aTupleInt.getZ());
+ }
+
+ void testOperatorEqualUnequal()
+ {
+ B3DTuple aTuple(4.0, 8.0, 9.0);
+ B3DTuple aTuple2 = aTuple;
+
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == aTuple);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == aTuple2);
+ CPPUNIT_ASSERT_EQUAL(true, aTuple == B3DTuple(4.0, 8.0, 9.0));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple == B3DTuple(4.0, 7.99, 9.0));
+ CPPUNIT_ASSERT_EQUAL(false, aTuple == B3DTuple(3.99, 8.0, 9.0));
+
+ CPPUNIT_ASSERT_EQUAL(false, aTuple != aTuple);
+ CPPUNIT_ASSERT_EQUAL(false, aTuple != aTuple2);
+ CPPUNIT_ASSERT_EQUAL(false, aTuple != B3DTuple(4.0, 8.0, 9.0));
+ CPPUNIT_ASSERT_EQUAL(true, aTuple != B3DTuple(4.0, 7.99, 9.0));
+ CPPUNIT_ASSERT_EQUAL(true, aTuple != B3DTuple(3.99, 8.0, 9.0));
+
+ B3ITuple aTupleInt(4, 8, 9);
+ B3ITuple aTupleInt2 = aTupleInt;
+
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == aTupleInt);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == aTupleInt2);
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt == B3ITuple(4, 8, 9));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt == B3ITuple(4, 7, 9));
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt == B3ITuple(3, 8, 9));
+
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt != aTupleInt);
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt != aTupleInt2);
+ CPPUNIT_ASSERT_EQUAL(false, aTupleInt != B3ITuple(4, 8, 9));
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt != B3ITuple(4, 7, 9));
+ CPPUNIT_ASSERT_EQUAL(true, aTupleInt != B3ITuple(3, 8, 9));
+ }
+
+ void testOperatorMinus()
+ {
+ B3DTuple aTupleMinus = -B3DTuple(4.0, 8.0, 1.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-4.0, aTupleMinus.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-8.0, aTupleMinus.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, aTupleMinus.getZ(), 1e-2);
+ B3DTuple aTupleZero = -B3DTuple(0.0, 0.0, 0.0);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero.getX(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero.getY(), 1e-2);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, aTupleZero.getZ(), 1e-2);
+
+ B3ITuple aTupleIntMinus = -B3ITuple(4, 8, 1);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-4), aTupleIntMinus.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-8), aTupleIntMinus.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), aTupleIntMinus.getZ());
+ B3ITuple aTupleIntZero = -B3ITuple(0, 0, 0);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero.getX());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero.getY());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aTupleIntZero.getZ());
+ }
+
+ CPPUNIT_TEST_SUITE(B3DTupleTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testEquals);
+ CPPUNIT_TEST(testOperatorAddition);
+ CPPUNIT_TEST(testOperatorSubstraction);
+ CPPUNIT_TEST(testOperatorMultiply);
+ CPPUNIT_TEST(testOperatorDivide);
+ CPPUNIT_TEST(testOperatorEqualUnequal);
+ CPPUNIT_TEST(testOperatorMinus);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+} // namespace basegfx
+
+CPPUNIT_TEST_SUITE_REGISTRATION(basegfx::B3DTupleTest);
+
+/* 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 000000000000..e38dd1542207
--- /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 <sal/types.h>
+#include <basegfx/basegfxdllapi.h>
+#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; }
+
+ // comparators with tolerance
+
+ template <typename T = TYPE,
+ typename std::enable_if<std::is_integral<T>::value, bool>::type = false>
+ bool equal(const Tuple2D<TYPE>& rTup) const
+ {
+ return mfX == rTup.mfX && mfY == rTup.mfY;
+ }
+
+ template <typename T = TYPE,
+ typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false>
+ bool equal(const Tuple2D<TYPE>& rTup) const
+ {
+ return this == &rTup || (fTools::equal(mfX, rTup.mfX) && fTools::equal(mfY, rTup.mfY));
+ }
+
+ template <typename T = TYPE,
+ typename std::enable_if<std::is_integral<T>::value, bool>::type = false>
+ bool equalZero() const
+ {
+ return mnX == 0 && mnY == 0;
+ }
+
+ template <typename T = TYPE,
+ typename std::enable_if<std::is_floating_point<T>::value, bool>::type = false>
+ 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 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: */
diff --git a/include/basegfx/tuple/b2dtuple.hxx b/include/basegfx/tuple/b2dtuple.hxx
index 0c7b7f463261..c523501b9639 100644
--- a/include/basegfx/tuple/b2dtuple.hxx
+++ b/include/basegfx/tuple/b2dtuple.hxx
@@ -22,7 +22,7 @@
#include <sal/types.h>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/basegfxdllapi.h>
-#include <basegfx/utils/common.hxx>
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -36,12 +36,8 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two double values
*/
- class SAL_WARN_UNUSED B2DTuple
+ class SAL_WARN_UNUSED B2DTuple : public Tuple2D<double>
{
- protected:
- double mfX;
- double mfY;
-
public:
/** Create a 2D Tuple
@@ -49,8 +45,7 @@ namespace basegfx
The tuple is initialized to (0.0, 0.0)
*/
B2DTuple()
- : mfX(0.0),
- mfY(0.0)
+ : Tuple2D(0.0, 0.0)
{}
/** Create a 2D Tuple
@@ -64,8 +59,7 @@ namespace basegfx
of the 2D Tuple.
*/
B2DTuple(double fX, double fY)
- : mfX( fX ),
- mfY( fY )
+ : Tuple2D(fX, fY)
{}
/** Create a copy of a 2D integer Tuple
@@ -75,120 +69,13 @@ namespace basegfx
*/
BASEGFX_DLLPUBLIC explicit B2DTuple(const B2ITuple& rTup);
- /// Get X-Coordinate of 2D Tuple
- double getX() const
- {
- return mfX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- double getY() const
- {
- return mfY;
- }
-
- /// Set X-Coordinate of 2D Tuple
- void setX(double fX)
- {
- mfX = fX;
- }
-
- /// Set Y-Coordinate of 2D Tuple
- void setY(double fY)
- {
- mfY = fY;
- }
-
- double get(Axis2D eAxis)
- {
- return eAxis == Axis2D::X ? getX() : getY();
- }
-
- void set(Axis2D eAxis, double fValue)
- {
- if (eAxis == Axis2D::X)
- setX(fValue);
- else
- setY(fValue);
- }
-
- // comparators with tolerance
-
- bool equalZero() const
- {
- return (this == &getEmptyTuple() ||
- (fTools::equalZero(mfX) && fTools::equalZero(mfY)));
- }
-
- bool equal(const B2DTuple& rTup) const
- {
- return (
- this == &rTup ||
- (fTools::equal(mfX, rTup.mfX) &&
- fTools::equal(mfY, rTup.mfY)));
- }
-
// operators
-
- B2DTuple& operator+=( const B2DTuple& rTup )
- {
- mfX += rTup.mfX;
- mfY += rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator-=( const B2DTuple& rTup )
- {
- mfX -= rTup.mfX;
- mfY -= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator/=( const B2DTuple& rTup )
- {
- mfX /= rTup.mfX;
- mfY /= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator*=( const B2DTuple& rTup )
- {
- mfX *= rTup.mfX;
- mfY *= rTup.mfY;
- return *this;
- }
-
- B2DTuple& operator*=(double t)
- {
- mfX *= t;
- mfY *= t;
- return *this;
- }
-
- B2DTuple& operator/=(double t)
- {
- const double fVal(1.0 / t);
- mfX *= fVal;
- mfY *= fVal;
- return *this;
- }
-
B2DTuple operator-(void) const
{
return B2DTuple(-mfX, -mfY);
}
- bool operator==( const B2DTuple& rTup ) const
- {
- return mfX == rTup.mfX && mfY == rTup.mfY;
- }
-
- bool operator!=( const B2DTuple& rTup ) const
- {
- return mfX != rTup.mfX || mfY != rTup.mfY;
- }
-
BASEGFX_DLLPUBLIC static const B2DTuple& getEmptyTuple();
};
diff --git a/include/basegfx/tuple/b2i64tuple.hxx b/include/basegfx/tuple/b2i64tuple.hxx
index 5f2350b66ac1..70838572f321 100644
--- a/include/basegfx/tuple/b2i64tuple.hxx
+++ b/include/basegfx/tuple/b2i64tuple.hxx
@@ -21,7 +21,7 @@
#include <sal/types.h>
#include <basegfx/basegfxdllapi.h>
-
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -33,34 +33,29 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two sal_Int64 values
*/
- class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2I64Tuple final
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2I64Tuple : public Tuple2D<sal_Int64>
{
- sal_Int64 mnX;
- sal_Int64 mnY;
-
public:
/** Create a 2D Tuple
The tuple is initialized to (0, 0)
*/
B2I64Tuple()
- : mnX(0),
- mnY(0)
+ : Tuple2D(0, 0)
{}
/** Create a 2D Tuple
- @param fX
+ @param nX
This parameter is used to initialize the X-coordinate
of the 2D Tuple.
- @param fY
+ @param nY
This parameter is used to initialize the Y-coordinate
of the 2D Tuple.
*/
- B2I64Tuple(sal_Int64 fX, sal_Int64 fY)
- : mnX( fX ),
- mnY( fY )
+ B2I64Tuple(sal_Int64 nX, sal_Int64 nY)
+ : Tuple2D(nX, nY)
{}
/** Create a copy of a 2D Tuple
@@ -69,100 +64,16 @@ namespace basegfx
The 2D Tuple which will be copied.
*/
B2I64Tuple(const B2I64Tuple& rTup)
- : mnX( rTup.mnX ),
- mnY( rTup.mnY )
+ : Tuple2D(rTup.mnX, rTup.mnY)
{}
- /// Get X-Coordinate of 2D Tuple
- sal_Int64 getX() const
- {
- return mnX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- sal_Int64 getY() const
- {
- return mnY;
- }
-
- /// Array-access to 2D Tuple
- const sal_Int64& operator[] (int nPos) const
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int64 members can be accessed as an array a shortcut is used here.
- // if(0 == nPos) return mnX; return mnY;
- return *((&mnX) + nPos);
- }
-
- /// Array-access to 2D Tuple
- sal_Int64& operator[] (int nPos)
- {
- // Here, normally one if(...) should be used. In the assumption that
- // both sal_Int64 members can be accessed as an array a shortcut is used here.
- // if(0 == nPos) return mnX; return mnY;
- return *((&mnX) + nPos);
- }
-
// operators
-
- B2I64Tuple& operator+=( const B2I64Tuple& rTup )
- {
- mnX += rTup.mnX;
- mnY += rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator-=( const B2I64Tuple& rTup )
- {
- mnX -= rTup.mnX;
- mnY -= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator/=( const B2I64Tuple& rTup )
- {
- mnX /= rTup.mnX;
- mnY /= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator*=( const B2I64Tuple& rTup )
- {
- mnX *= rTup.mnX;
- mnY *= rTup.mnY;
- return *this;
- }
-
- B2I64Tuple& operator*=(sal_Int64 t)
- {
- mnX *= t;
- mnY *= t;
- return *this;
- }
-
- B2I64Tuple& operator/=(sal_Int64 t)
- {
- mnX /= t;
- mnY /= t;
- return *this;
- }
-
B2I64Tuple operator-(void) const
{
return B2I64Tuple(-mnX, -mnY);
}
- bool operator==( const B2I64Tuple& rTup ) const
- {
- return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
- }
-
- bool operator!=( const B2I64Tuple& rTup ) const
- {
- return !(*this == rTup);
- }
-
B2I64Tuple& operator=( const B2I64Tuple& rTup )
{
mnX = rTup.mnX;
diff --git a/include/basegfx/tuple/b2ituple.hxx b/include/basegfx/tuple/b2ituple.hxx
index b8f6c3e96386..e3f195596a37 100644
--- a/include/basegfx/tuple/b2ituple.hxx
+++ b/include/basegfx/tuple/b2ituple.hxx
@@ -21,6 +21,7 @@
#include <sal/types.h>
#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple2D.hxx>
namespace basegfx
{
@@ -32,143 +33,37 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on two sal_Int32 values
*/
- class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B2ITuple : public Tuple2D<sal_Int32>
{
- protected:
- sal_Int32 mnX;
- sal_Int32 mnY;
-
public:
/** Create a 2D Tuple
The tuple is initialized to (0, 0)
*/
B2ITuple()
- : mnX(0),
- mnY(0)
+ : Tuple2D(0, 0)
{}
/** Create a 2D Tuple
- @param fX
+ @param nX
This parameter is used to initialize the X-coordinate
of the 2D Tuple.
- @param fY
+ @param nY
This parameter is used to initialize the Y-coordinate
of the 2D Tuple.
*/
- B2ITuple(sal_Int32 fX, sal_Int32 fY)
- : mnX( fX ),
- mnY( fY )
+ B2ITuple(sal_Int32 nX, sal_Int32 nY)
+ : Tuple2D(nX, nY)
{}
- /// Get X-Coordinate of 2D Tuple
- sal_Int32 getX() const
- {
- return mnX;
- }
-
- /// Get Y-Coordinate of 2D Tuple
- sal_Int32 getY() const
- {
- return mnY;
- }
-
- /// Set X-Coordinate of 2D Tuple
- void setX(sal_Int32 fX)
- {
- mnX = fX;
- }
-
- /// Set Y-Coordinate of 2D Tuple
- void setY(sal_Int32 fY)
- {
- mnY = fY;
- }
-
- /// Array-access to 2D Tuple
- const sal_Int32& operator[] (int nPos) const
- {
- // Here, normally one if(...) 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; return mnY;
- return *((&mnX) + nPos);
- }
-
- /// Array-access to 2D Tuple
- sal_Int32& operator[] (int nPos)
- {
- // Here, normally one if(...) 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; return mnY;
- return *((&mnX) + nPos);
- }
-
// operators
-
- B2ITuple& operator+=( const B2ITuple& rTup )
- {
- mnX += rTup.mnX;
- mnY += rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator-=( const B2ITuple& rTup )
- {
- mnX -= rTup.mnX;
- mnY -= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator/=( const B2ITuple& rTup )
- {
- mnX /= rTup.mnX;
- mnY /= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator*=( const B2ITuple& rTup )
- {
- mnX *= rTup.mnX;
- mnY *= rTup.mnY;
- return *this;
- }
-
- B2ITuple& operator*=(sal_Int32 t)
- {
- mnX *= t;
- mnY *= t;
- return *this;
- }
-
- B2ITuple& operator/=(sal_Int32 t)
- {
- mnX /= t;
- mnY /= t;
- return *this;
- }
-
B2ITuple operator-(void) const
{
return B2ITuple(-mnX, -mnY);
}
-
- bool equalZero() const
- {
- return mnX == 0 && mnY == 0;
- }
-
- bool operator==( const B2ITuple& rTup ) const
- {
- return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY);
- }
-
- bool operator!=( const B2ITuple& rTup ) const
- {
- return !(*this == rTup);
- }
};
// external operators
diff --git a/include/basegfx/tuple/b3dtuple.hxx b/include/basegfx/tuple/b3dtuple.hxx
index 791cc5f3e667..bb8f4b4067c3 100644
--- a/include/basegfx/tuple/b3dtuple.hxx
+++ b/include/basegfx/tuple/b3dtuple.hxx
@@ -23,6 +23,7 @@
#include <sal/types.h>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple3D.hxx>
namespace basegfx
{
@@ -36,22 +37,15 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on three double values
*/
- class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) B3DTuple
+ class SAL_WARN_UNUSED UNLESS_MERGELIBS(BASEGFX_DLLPUBLIC) B3DTuple : public Tuple3D<double>
{
- protected:
- double mfX;
- double mfY;
- double mfZ;
-
public:
/** Create a 3D Tuple
The tuple is initialized to (0.0, 0.0, 0.0)
*/
B3DTuple()
- : mfX(0.0),
- mfY(0.0),
- mfZ(0.0)
+ : Tuple3D(0.0, 0.0, 0.0)
{}
/** Create a 3D Tuple
@@ -69,47 +63,9 @@ namespace basegfx
of the 3D Tuple.
*/
B3DTuple(double fX, double fY, double fZ)
- : mfX(fX),
- mfY(fY),
- mfZ(fZ)
+ : Tuple3D(fX, fY, fZ)
{}
- /// get X-Coordinate of 3D Tuple
- double getX() const
- {
- return mfX;
- }
-
- /// get Y-Coordinate of 3D Tuple
- double getY() const
- {
- return mfY;
- }
-
- /// get Z-Coordinate of 3D Tuple
- double getZ() const
- {
- return mfZ;
- }
-
- /// set X-Coordinate of 3D Tuple
- void setX(double fX)
- {
- mfX = fX;
- }
-
- /// set Y-Coordinate of 3D Tuple
- void setY(double fY)
- {
- mfY = fY;
- }
-
- /// set Z-Coordinate of 3D Tuple
- void setZ(double fZ)
- {
- mfZ = fZ;
- }
-
/// Array-access to 3D Tuple
const double& operator[] (int nPos) const
{
@@ -150,70 +106,17 @@ namespace basegfx
// operators
-
- B3DTuple& operator+=( const B3DTuple& rTup )
- {
- mfX += rTup.mfX;
- mfY += rTup.mfY;
- mfZ += rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator-=( const B3DTuple& rTup )
- {
- mfX -= rTup.mfX;
- mfY -= rTup.mfY;
- mfZ -= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator/=( const B3DTuple& rTup )
- {
- mfX /= rTup.mfX;
- mfY /= rTup.mfY;
- mfZ /= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator*=( const B3DTuple& rTup )
- {
- mfX *= rTup.mfX;
- mfY *= rTup.mfY;
- mfZ *= rTup.mfZ;
- return *this;
- }
-
- B3DTuple& operator*=(double t)
- {
- mfX *= t;
- mfY *= t;
- mfZ *= t;
- return *this;
- }
-
- B3DTuple& operator/=(double t)
- {
- const double fVal(1.0 / t);
- mfX *= fVal;
- mfY *= fVal;
- mfZ *= fVal;
- return *this;
- }
-
B3DTuple operator-(void) const
{
return B3DTuple(-mfX, -mfY, -mfZ);
}
- bool operator==( const B3DTuple& rTup ) const
+ bool operator==(const B3DTuple& rTup) const
{
return mfX == rTup.mfX && mfY == rTup.mfY && mfZ == rTup.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)
{
diff --git a/include/basegfx/tuple/b3ituple.hxx b/include/basegfx/tuple/b3ituple.hxx
index 7fe49ea92e93..72c9fa81402a 100644
--- a/include/basegfx/tuple/b3ituple.hxx
+++ b/include/basegfx/tuple/b3ituple.hxx
@@ -21,6 +21,7 @@
#include <sal/types.h>
#include <basegfx/basegfxdllapi.h>
+#include <basegfx/tuple/Tuple3D.hxx>
namespace basegfx
{
@@ -32,22 +33,15 @@ namespace basegfx
@derive Use this class to implement Points or Vectors
which are based on three sal_Int32 values
*/
- class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3ITuple
+ class SAL_WARN_UNUSED BASEGFX_DLLPUBLIC B3ITuple : public Tuple3D<sal_Int32>
{
- protected:
- sal_Int32 mnX;
- sal_Int32 mnY;
- sal_Int32 mnZ;
-
public:
/** Create a 3D Tuple
The tuple is initialized to (0, 0, 0)
*/
B3ITuple()
- : mnX(0),
- mnY(0),
- mnZ(0)
+ : Tuple3D(0, 0, 0)
{}
/** Create a 3D Tuple
@@ -65,23 +59,9 @@ namespace basegfx
of the 3D Tuple.
*/
B3ITuple(sal_Int32 nX, sal_Int32 nY, sal_Int32 nZ)
- : mnX(nX),
- mnY(nY),
- mnZ(nZ)
+ : Tuple3D(nX, nY, nZ)
{}
- /// get X-Coordinate of 3D Tuple
- sal_Int32 getX() const
- {
- return mnX;
- }
-
- /// get Y-Coordinate of 3D Tuple
- sal_Int32 getY() const
- {
- return mnY;
- }
-
/// Array-access to 3D Tuple
const sal_Int32& operator[] (int nPos) const
{
@@ -102,69 +82,10 @@ namespace basegfx
// operators
-
- B3ITuple& operator+=( const B3ITuple& rTup )
- {
- mnX += rTup.mnX;
- mnY += rTup.mnY;
- mnZ += rTup.mnZ;
- return *this;
- }
-
- B3ITuple& operator-=( const B3ITuple& rTup )
- {
- mnX -= rTup.mnX;
- mnY -= rTup.mnY;
- mnZ -= rTup.mnZ;
- return *this;
- }
-
- B3ITuple& operator/=( const B3ITuple& rTup )
- {
- mnX /= rTup.mnX;
- mnY /= rTup.mnY;
- mnZ /= rTup.mnZ;
- return *this;
- }
-
- B3ITuple& operator*=( const B3ITuple& rTup )
- {
- mnX *= rTup.mnX;
- mnY *= rTup.mnY;
- mnZ *= rTup.mnZ;
- return *this;
- }
-
- B3ITuple& operator*=(sal_Int32 t)
- {
- mnX *= t;
- mnY *= t;
- mnZ *= t;
- return *this;
- }
-
- B3ITuple& operator/=(sal_Int32 t)
- {
- mnX /= t;
- mnY /= t;
- mnZ /= t;
- return *this;
- }
-
B3ITuple operator-(void) const
{
return B3ITuple(-mnX, -mnY, -mnZ);
}
-
- bool operator==( const B3ITuple& rTup ) const
- {
- return this == &rTup || (rTup.mnX == mnX && rTup.mnY == mnY && rTup.mnZ == mnZ);
- }
-
- bool operator!=( const B3ITuple& rTup ) const
- {
- return !(*this == rTup);
- }
};
} // end of namespace basegfx