From 233360e3ea0d6d4acea76a7d9e7ce7700ea80b1a Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 25 Apr 2017 15:08:04 -0400 Subject: Add unittest for matrix reverse This Cl adds some unit tests for the CFX_Matrix Reverse method. Bug: chromium:702041 Change-Id: I9598d3eb48d6b86a3e192d313fe1091bd29a4701 Reviewed-on: https://pdfium-review.googlesource.com/4492 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- BUILD.gn | 1 + core/fxcrt/fx_coordinates_unittest.cpp | 89 ++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 core/fxcrt/fx_coordinates_unittest.cpp diff --git a/BUILD.gn b/BUILD.gn index e513b37e05..a11c2c179e 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1872,6 +1872,7 @@ test("pdfium_unittests") { "core/fxcrt/fx_basic_gcc_unittest.cpp", "core/fxcrt/fx_basic_util_unittest.cpp", "core/fxcrt/fx_bidi_unittest.cpp", + "core/fxcrt/fx_coordinates_unittest.cpp", "core/fxcrt/fx_extension_unittest.cpp", "core/fxcrt/fx_memory_unittest.cpp", "core/fxcrt/fx_system_unittest.cpp", diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp new file mode 100644 index 0000000000..12ddb97330 --- /dev/null +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -0,0 +1,89 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "core/fxcrt/fx_coordinates.h" + +#include "testing/gtest/include/gtest/gtest.h" + +TEST(CFX_Matrix, ReverseIdentity) { + CFX_Matrix m; + CFX_Matrix rev; + + m.SetIdentity(); + rev.SetReverse(m); + EXPECT_FLOAT_EQ(1.0, rev.a); + EXPECT_FLOAT_EQ(0.0, rev.b); + EXPECT_FLOAT_EQ(0.0, rev.c); + EXPECT_FLOAT_EQ(1.0, rev.d); + EXPECT_FLOAT_EQ(0.0, rev.e); + EXPECT_FLOAT_EQ(0.0, rev.f); + + CFX_PointF expected(2, 3); + CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3))); + EXPECT_FLOAT_EQ(expected.x, result.x); + EXPECT_FLOAT_EQ(expected.y, result.y); +} + +TEST(CFX_Matrix, Reverse) { + float data[6] = {3, 0, 2, 3, 1, 4}; + CFX_Matrix m(data); + CFX_Matrix rev; + + rev.SetReverse(m); + EXPECT_FLOAT_EQ(0.33333334f, rev.a); + EXPECT_FLOAT_EQ(0.0f, rev.b); + EXPECT_FLOAT_EQ(-0.22222222f, rev.c); + EXPECT_FLOAT_EQ(0.33333334f, rev.d); + EXPECT_FLOAT_EQ(0.55555556f, rev.e); + EXPECT_FLOAT_EQ(-1.3333334f, rev.f); + + CFX_PointF expected(2, 3); + CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3))); + EXPECT_FLOAT_EQ(expected.x, result.x); + EXPECT_FLOAT_EQ(expected.y, result.y); +} + +// Note, I think these are a bug and the matrix should be the identity. +TEST(CFX_Matrix, ReverseCR702041) { + // The determinate is < std::numeric_limits::epsilon() + float data[6] = {0.947368443f, -0.108947366f, -0.923076928f, + 0.106153846f, 18.0f, 787.929993f}; + CFX_Matrix m(data); + CFX_Matrix rev; + + rev.SetReverse(m); + EXPECT_FLOAT_EQ(14247728.0f, rev.a); + EXPECT_FLOAT_EQ(14622668.0f, rev.b); + EXPECT_FLOAT_EQ(1.2389329e+08f, rev.c); + EXPECT_FLOAT_EQ(1.2715364e+08f, rev.d); + EXPECT_FLOAT_EQ(-9.7875698e+10f, rev.e); + EXPECT_FLOAT_EQ(-1.0045138e+11f, rev.f); + + // Should be 2, 3 + CFX_PointF expected(0, 0); + CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3))); + EXPECT_FLOAT_EQ(expected.x, result.x); + EXPECT_FLOAT_EQ(expected.y, result.y); +} + +TEST(CFX_Matrix, ReverseCR714187) { + // The determinate is < std::numeric_limits::epsilon() + float data[6] = {0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f, 136.977646f}; + CFX_Matrix m(data); + CFX_Matrix rev; + + rev.SetReverse(m); + EXPECT_FLOAT_EQ(27027.025f, rev.a); + EXPECT_FLOAT_EQ(0.0f, rev.b); + EXPECT_FLOAT_EQ(0.0f, rev.c); + EXPECT_FLOAT_EQ(-27027.025f, rev.d); + EXPECT_FLOAT_EQ(-4930083.5f, rev.e); + EXPECT_FLOAT_EQ(3702098.2f, rev.f); + + // Should be 3 .... + CFX_PointF expected(2, 2.75); + CFX_PointF result = rev.Transform(m.Transform(CFX_PointF(2, 3))); + EXPECT_FLOAT_EQ(expected.x, result.x); + EXPECT_FLOAT_EQ(expected.y, result.y); +} -- cgit v1.2.3