summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--basegfx/test/B2DHomMatrixTest.cxx181
-rw-r--r--include/basegfx/matrix/Matrix.hxx178
2 files changed, 59 insertions, 300 deletions
diff --git a/basegfx/test/B2DHomMatrixTest.cxx b/basegfx/test/B2DHomMatrixTest.cxx
index 340f37c8937f..8063587ac2dd 100644
--- a/basegfx/test/B2DHomMatrixTest.cxx
+++ b/basegfx/test/B2DHomMatrixTest.cxx
@@ -23,7 +23,6 @@
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
-#include <basegfx/matrix/Matrix.hxx>
#include <basegfx/numeric/ftools.hxx>
#include <basegfx/tuple/b2dtuple.hxx>
#include <basegfx/range/b2drange.hxx>
@@ -446,127 +445,62 @@ public:
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("decompose: error test J1", F_PI, fDRot, 1E-12);
}
- void testMatrix()
+ void testCreate_abcdef()
{
- {
- 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);
- }
+ B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(00, aB2DMatrix.a(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(10, aB2DMatrix.b(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(01, aB2DMatrix.c(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(11, aB2DMatrix.d(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(02, aB2DMatrix.e(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(12, aB2DMatrix.f(), 1E-12);
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 0), aB2DMatrix.a(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 0), aB2DMatrix.b(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 1), aB2DMatrix.c(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 1), aB2DMatrix.d(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(0, 2), aB2DMatrix.e(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(aB2DMatrix.get(1, 2), aB2DMatrix.f(), 1E-12);
+ }
+
+ void testMultiplyWithAnotherMatrix()
+ {
+ B2DHomMatrix aB2DMatrix(00, 01, 02, 10, 11, 12);
+ B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
+
+ 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);
+ }
+
+ void testTransformPoint()
+ {
+ B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
+
+ B2DPoint aPoint(1, 2);
+ aPoint *= aNewB2DMatrix;
+
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(12, aPoint.getX(), 1E-12);
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(16, aPoint.getY(), 1E-12);
+ }
+
+ void testTransformRange()
+ {
+ B2DHomMatrix aNewB2DMatrix = B2DHomMatrix::abcdef(1, 2, 3, 4, 5, 6);
+
+ 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
@@ -582,7 +516,10 @@ public:
CPPUNIT_TEST(shear);
CPPUNIT_TEST(multiply);
CPPUNIT_TEST(decompose);
- CPPUNIT_TEST(testMatrix);
+ CPPUNIT_TEST(testCreate_abcdef);
+ CPPUNIT_TEST(testMultiplyWithAnotherMatrix);
+ CPPUNIT_TEST(testTransformPoint);
+ CPPUNIT_TEST(testTransformRange);
CPPUNIT_TEST_SUITE_END();
}; // class b2dhommatrix
diff --git a/include/basegfx/matrix/Matrix.hxx b/include/basegfx/matrix/Matrix.hxx
deleted file mode 100644
index e690216a3824..000000000000
--- a/include/basegfx/matrix/Matrix.hxx
+++ /dev/null
@@ -1,178 +0,0 @@
-/* -*- 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
-
-class Matrix
-{
-public:
- Matrix()
- : Matrix(1, 0, 0, 1, 0, 0)
- {
- }
-
- Matrix(const Matrix& other)
- : Matrix(other.ma, other.mb, other.mc, other.md, other.me, other.mf)
- {
- }
-
- Matrix(double da, double db, double dc, double dd, double de, double df)
- : ma(da)
- , mb(db)
- , mc(dc)
- , md(dd)
- , me(de)
- , mf(df)
- {
- }
-
- const Matrix& operator=(const Matrix& other)
- {
- ma = other.ma;
- mb = other.mb;
- mc = other.mc;
- md = other.md;
- me = other.me;
- mf = other.mf;
- return *this;
- }
-
- double get(sal_uInt16 nRow, sal_uInt16 nColumn) const
- {
- if (nRow == 0)
- {
- if (nColumn == 0)
- return v00;
- else if (nColumn == 1)
- return v01;
- else if (nColumn == 2)
- return v02;
- }
- else if (nRow == 1)
- {
- if (nColumn == 0)
- return v10;
- else if (nColumn == 1)
- return v11;
- else if (nColumn == 2)
- return v12;
- }
- return 0.0;
- }
-
- double a() const { return ma; }
- double b() const { return mb; }
- double c() const { return mc; }
- double d() const { return md; }
- double e() const { return me; }
- double f() const { return mf; }
-
- /// Multiply this * other.
- void Concatinate(const Matrix& other)
- {
- double newA = ma * other.ma + mb * other.mc;
- double newB = ma * other.mb + mb * other.md;
- double newC = mc * other.ma + md * other.mc;
- double newD = mc * other.mb + md * other.md;
- double newE = me * other.ma + mf * other.mc + other.me;
- double newF = me * other.mb + mf * other.md + other.mf;
-
- ma = newA;
- mb = newB;
- mc = newC;
- md = newD;
- me = newE;
- mf = newF;
- }
-
- /// Transform the point (x, y) by this Matrix.
- template <typename T> void Transform(T& x, T& y)
- {
- T newX = v00 * x + v01 * y + v02;
- T newY = v10 * x + v11 * y + v12;
- x = newX;
- y = newY;
- }
-
- /// Transform the rectangle (left, right, top, bottom) by this Matrix.
- template <typename T> void Transform(T& left, T& right, T& top, T& bottom)
- {
- T leftTopX = left;
- T leftTopY = top;
- Transform(leftTopX, leftTopY);
-
- T leftBottomX = left;
- T leftBottomY = bottom;
- Transform(leftBottomX, leftBottomY);
-
- T rightTopX = right;
- T rightTopY = top;
- Transform(rightTopX, rightTopY);
-
- T rightBottomX = right;
- T rightBottomY = bottom;
- Transform(rightBottomX, rightBottomY);
-
- left = std::min(leftTopX, leftBottomX);
- right = std::max(rightTopX, rightBottomX);
-
- if (top > bottom)
- top = std::max(leftTopY, rightTopY);
- else
- top = std::min(leftTopY, rightTopY);
-
- if (top > bottom)
- bottom = std::max(leftBottomY, rightBottomY);
- else
- bottom = std::min(leftBottomY, rightBottomY);
- }
-
- std::string toString() const
- {
- std::ostringstream oss;
- oss << '(' << ma << ", " << mb << ", " << mc << ", " << md << ", " << me << ", " << mf
- << ')';
- return oss.str();
- }
-
-private:
- union {
- struct
- {
- double ma;
- double mb;
- double mc;
- double md;
- double me;
- double mf;
- };
-
- struct
- {
- double v00;
- double v10;
- double v01;
- double v11;
- double v02;
- double v12;
- };
- };
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */