From 68ccd87c9e950572e859eb5147453be2a528b944 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 26 Jan 2019 16:48:41 -0500 Subject: Move rectangle transformation into QPDFMatrix --- libtests/matrix.cc | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'libtests/matrix.cc') 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; } -- cgit v1.2.3-54-g00ecf