From 60f14ad158801183519ff929167b8526b7941670 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Sat, 28 Mar 2020 20:27:17 +0100 Subject: basegfx: test B2DHomMatrix and Matrix together MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds a test for B2DHomMatix and Matrix to test them together. Ther reason for this is that we can remove Matrix in favour to B2DHomMatrix, but first we need to make sure it is safe so by checking that the operations in Matrix yield the same result as with B2DHomMatrix. Change-Id: Ia93c1d3c7b2b7ff257c35831ff31afad3e8f34ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91312 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- basegfx/test/B2DHomMatrixTest.cxx | 126 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) (limited to 'basegfx/test') diff --git a/basegfx/test/B2DHomMatrixTest.cxx b/basegfx/test/B2DHomMatrixTest.cxx index 52ab3e77ad5e..340f37c8937f 100644 --- a/basegfx/test/B2DHomMatrixTest.cxx +++ b/basegfx/test/B2DHomMatrixTest.cxx @@ -23,8 +23,10 @@ #include #include +#include #include #include +#include namespace basegfx { @@ -444,6 +446,129 @@ public: CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", F_PI, fDRot, 1E-12); } + void testMatrix() + { + { + B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12); + Matrix aMatrix(00, 10, 01, 11, 02, 12); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aMatrix.a(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aMatrix.b(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aMatrix.c(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aMatrix.d(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aMatrix.e(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aMatrix.f(), 1E-12); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aMatrix.get(0, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aMatrix.get(1, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aMatrix.get(0, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aMatrix.get(1, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aMatrix.get(0, 2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aMatrix.get(1, 2), 1E-12); + } + + { + B2DHomMatrix aB2DMatrix = B2DHomMatrix::abcdef(00, 10, 01, 11, 02, 12); + Matrix aMatrix(00, 10, 01, 11, 02, 12); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aMatrix.a(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aMatrix.b(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aMatrix.c(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aMatrix.d(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aMatrix.e(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aMatrix.f(), 1E-12); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aMatrix.get(0, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aMatrix.get(1, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aMatrix.get(0, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aMatrix.get(1, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aMatrix.get(0, 2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aMatrix.get(1, 2), 1E-12); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.a(), aMatrix.a(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.b(), aMatrix.b(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.c(), aMatrix.c(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.d(), aMatrix.d(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.e(), aMatrix.e(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.f(), aMatrix.f(), 1E-12); + } + + { + B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12); //column first + Matrix aMatrix(00, 10, 01, 11, 02, 12); // row first + + Matrix aNewMatrix(1, 2, 3, 4, 5, 6); + + B2DHomMatrix aNewB2DMatrix(1, 3, 5, 2, 4, 6); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(0, 0), aNewB2DMatrix.get(0, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(1, 0), aNewB2DMatrix.get(1, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(0, 1), aNewB2DMatrix.get(0, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(1, 1), aNewB2DMatrix.get(1, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(0, 2), aNewB2DMatrix.get(0, 2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(aNewMatrix.get(1, 2), aNewB2DMatrix.get(1, 2), 1E-12); + + aMatrix.Concatinate(aNewMatrix); + CPPUNIT_ASSERT_DOUBLES_EQUAL(30, aMatrix.get(0, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(40, aMatrix.get(1, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(34, aMatrix.get(0, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46, aMatrix.get(1, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(43, aMatrix.get(0, 2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(58, aMatrix.get(1, 2), 1E-12); + + aB2DMatrix *= aNewB2DMatrix; + + CPPUNIT_ASSERT_DOUBLES_EQUAL(30, aB2DMatrix.get(0, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(40, aB2DMatrix.get(1, 0), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(34, aB2DMatrix.get(0, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(46, aB2DMatrix.get(1, 1), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(43, aB2DMatrix.get(0, 2), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(58, aB2DMatrix.get(1, 2), 1E-12); + } + + { + Matrix aNewMatrix(1, 2, 3, 4, 5, 6); + B2DHomMatrix aNewB2DMatrix(1, 3, 5, 2, 4, 6); + + double x = 1; + double y = 2; + aNewMatrix.Transform(x, y); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(12, x, 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(16, y, 1E-12); + + B2DPoint aPoint(1, 2); + aPoint *= aNewB2DMatrix; + + CPPUNIT_ASSERT_DOUBLES_EQUAL(12, aPoint.getX(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(16, aPoint.getY(), 1E-12); + } + + { + Matrix aNewMatrix(1, 2, 3, 4, 5, 6); + B2DHomMatrix aNewB2DMatrix(1, 3, 5, 2, 4, 6); + + double left = 2; + double right = 4; + double top = 1; + double bottom = 3; + aNewMatrix.Transform(left, right, top, bottom); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(10, left, 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(18, right, 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(14, top, 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(26, bottom, 1E-12); + + B2DRange aRange(2, 1, 4, 3); + aRange *= aNewB2DMatrix; + + CPPUNIT_ASSERT_DOUBLES_EQUAL(10, aRange.getMinX(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(18, aRange.getMaxX(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(14, aRange.getMinY(), 1E-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL(26, aRange.getMaxY(), 1E-12); + } + } + // 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. @@ -457,6 +582,7 @@ public: CPPUNIT_TEST(shear); CPPUNIT_TEST(multiply); CPPUNIT_TEST(decompose); + CPPUNIT_TEST(testMatrix); CPPUNIT_TEST_SUITE_END(); }; // class b2dhommatrix -- cgit