aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/matrix.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-12-24 22:28:08 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-01 00:23:47 +0100
commitdaeb5a85b6ded478aaac942c439ef5fd6bb8874f (patch)
treef83657f24a50c652ff833b4a93a6d2f55139282d /libtests/matrix.cc
parent3440ea7d3ca0bfb5d6fb4d7392b61017cb36bf0a (diff)
downloadqpdf-daeb5a85b6ded478aaac942c439ef5fd6bb8874f.tar.zst
Transformation matrix
Diffstat (limited to 'libtests/matrix.cc')
-rw-r--r--libtests/matrix.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/libtests/matrix.cc b/libtests/matrix.cc
new file mode 100644
index 00000000..d27e96cf
--- /dev/null
+++ b/libtests/matrix.cc
@@ -0,0 +1,55 @@
+#include <qpdf/QPDFMatrix.hh>
+#include <qpdf/QUtil.hh>
+#include <assert.h>
+#include <iostream>
+
+static void check(QPDFMatrix const& m, std::string const& exp)
+{
+ std::string u = m.unparse();
+ if (u != exp)
+ {
+ std::cout << "got " << u << ", wanted " << exp << std::endl;
+ }
+}
+
+static void check_xy(double x, double y, std::string const& exp)
+{
+ std::string u = (QUtil::double_to_string(x, 2) + " " +
+ QUtil::double_to_string(y, 2));
+ if (u != exp)
+ {
+ std::cout << "got " << u << ", wanted " << exp << std::endl;
+ }
+}
+
+int main()
+{
+ QPDFMatrix m;
+ check(m, "1.00000 0.00000 0.00000 1.00000 0.00000 0.00000");
+ m.translate(10, 20);
+ check(m, "1.00000 0.00000 0.00000 1.00000 10.00000 20.00000");
+ m.scale(1.5, 2);
+ check(m, "1.50000 0.00000 0.00000 2.00000 10.00000 20.00000");
+ m.translate(30, 40);
+ check(m, "1.50000 0.00000 0.00000 2.00000 55.00000 100.00000");
+ m.concat(QPDFMatrix(1, 2, 3, 4, 5, 6));
+ check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+ m.rotatex90(90);
+ check(m, "4.50000 8.00000 -1.50000 -4.00000 62.50000 112.00000");
+ m.rotatex90(180);
+ check(m, "-4.50000 -8.00000 1.50000 4.00000 62.50000 112.00000");
+ m.rotatex90(270);
+ check(m, "-1.50000 -4.00000 -4.50000 -8.00000 62.50000 112.00000");
+ m.rotatex90(180);
+ check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+ m.rotatex90(12345);
+ check(m, "1.50000 4.00000 4.50000 8.00000 62.50000 112.00000");
+
+ double xp = 0;
+ double yp = 0;
+ m.transform(240, 480, xp, yp);
+ check_xy(xp, yp, "2582.50 4912.00");
+
+ std::cout << "matrix tests done" << std::endl;
+ return 0;
+}