aboutsummaryrefslogtreecommitdiffstats
path: root/libtests
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-01-26 22:48:41 +0100
committerJay Berkenbilt <ejb@ql.org>2019-01-27 13:50:30 +0100
commit68ccd87c9e950572e859eb5147453be2a528b944 (patch)
tree1625df9dc46a45a7837021dbc5c70ed86425e93c /libtests
parent8cb245739c76a1766473174500275d5d8b215d98 (diff)
downloadqpdf-68ccd87c9e950572e859eb5147453be2a528b944.tar.zst
Move rectangle transformation into QPDFMatrix
Diffstat (limited to 'libtests')
-rw-r--r--libtests/matrix.cc34
1 files changed, 32 insertions, 2 deletions
diff --git a/libtests/matrix.cc b/libtests/matrix.cc
index f022ce4e..77a058ee 100644
--- a/libtests/matrix.cc
+++ b/libtests/matrix.cc
@@ -22,6 +22,25 @@ static void check_xy(double x, double y, std::string const& exp)
}
}
+static void check_rect(QPDFObjectHandle::Rectangle const& r,
+ double llx, double lly, double urx, double ury)
+{
+ std::string actual = (
+ QUtil::double_to_string(r.llx, 2) + " " +
+ QUtil::double_to_string(r.lly, 2) + " " +
+ QUtil::double_to_string(r.urx, 2) + " " +
+ QUtil::double_to_string(r.ury, 2));
+ std::string wanted = (
+ QUtil::double_to_string(llx, 2) + " " +
+ QUtil::double_to_string(lly, 2) + " " +
+ QUtil::double_to_string(urx, 2) + " " +
+ QUtil::double_to_string(ury, 2));
+ if (actual != wanted)
+ {
+ std::cout << "got " << actual << ", wanted " << wanted << std::endl;
+ }
+}
+
int main()
{
QPDFMatrix m;
@@ -30,8 +49,14 @@ int main()
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");
+ double xp = 0;
+ double yp = 0;
+ m.transform(10, 100, xp, yp);
+ check_xy(xp, yp, "25.00 220.00");
m.translate(30, 40);
check(m, "1.50000 0.00000 0.00000 2.00000 55.00000 100.00000");
+ m.transform(10, 100, xp, yp);
+ check_xy(xp, yp, "70.00 300.00");
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);
@@ -45,8 +70,6 @@ int main()
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");
@@ -55,6 +78,13 @@ int main()
"[3 1 4 1 5 9.26535]").getArrayAsMatrix()),
"3.00000 1.00000 4.00000 1.00000 5.00000 9.26535");
+ m = QPDFMatrix();
+ m.rotatex90(90);
+ m.translate(200, -100);
+ check_rect(
+ m.transformRectangle(QPDFObjectHandle::Rectangle(10, 20, 30, 50)),
+ 50, 210, 80, 230);
+
std::cout << "matrix tests done" << std::endl;
return 0;
}