From 02d42b65b779e29737275a258cb9f30fa8449e5e Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Wed, 24 Oct 2018 17:56:26 +0000 Subject: Add CFX_Matrix::AsTuple(). Change-Id: I53c1b148cb8cdc77461766fc9996a0a3ce5f4cb7 Reviewed-on: https://pdfium-review.googlesource.com/c/44536 Reviewed-by: Tom Sepez Commit-Queue: Lei Zhang --- core/fxcrt/fx_coordinates.cpp | 5 +++++ core/fxcrt/fx_coordinates.h | 5 +++-- core/fxcrt/fx_coordinates_unittest.cpp | 35 ++++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 14 deletions(-) (limited to 'core/fxcrt') diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp index 7d0d104122..fabde1e80b 100644 --- a/core/fxcrt/fx_coordinates.cpp +++ b/core/fxcrt/fx_coordinates.cpp @@ -300,6 +300,11 @@ std::ostream& operator<<(std::ostream& os, const CFX_RectF& rect) { } #endif // NDEBUG +std::tuple CFX_Matrix::AsTuple() + const { + return {a, b, c, d, e, f}; +} + CFX_Matrix CFX_Matrix::GetInverse() const { CFX_Matrix inverse; float i = a * d - b * c; diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index 08dbd08903..67d3736fd8 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -8,12 +8,11 @@ #define CORE_FXCRT_FX_COORDINATES_H_ #include +#include #include "core/fxcrt/fx_system.h" #include "third_party/base/numerics/safe_math.h" -class CFX_Matrix; - template class CFX_PTemplate { public: @@ -541,6 +540,8 @@ class CFX_Matrix { f = other.f; } + std::tuple AsTuple() const; + void SetIdentity() { a = 1; b = 0; diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp index 3d11748649..ded4d45c9d 100644 --- a/core/fxcrt/fx_coordinates_unittest.cpp +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -248,27 +248,38 @@ TEST(CFX_Matrix, ReverseIdentity) { TEST(CFX_Matrix, SetIdentity) { CFX_Matrix m; - EXPECT_FLOAT_EQ(1.0, m.a); - EXPECT_FLOAT_EQ(0.0, m.b); - EXPECT_FLOAT_EQ(0.0, m.c); - EXPECT_FLOAT_EQ(1.0, m.d); - EXPECT_FLOAT_EQ(0.0, m.e); - EXPECT_FLOAT_EQ(0.0, m.f); + EXPECT_FLOAT_EQ(1.0f, m.a); + EXPECT_FLOAT_EQ(0.0f, m.b); + EXPECT_FLOAT_EQ(0.0f, m.c); + EXPECT_FLOAT_EQ(1.0f, m.d); + EXPECT_FLOAT_EQ(0.0f, m.e); + EXPECT_FLOAT_EQ(0.0f, m.f); EXPECT_TRUE(m.IsIdentity()); m.a = -1; EXPECT_FALSE(m.IsIdentity()); m.SetIdentity(); - EXPECT_FLOAT_EQ(1.0, m.a); - EXPECT_FLOAT_EQ(0.0, m.b); - EXPECT_FLOAT_EQ(0.0, m.c); - EXPECT_FLOAT_EQ(1.0, m.d); - EXPECT_FLOAT_EQ(0.0, m.e); - EXPECT_FLOAT_EQ(0.0, m.f); + EXPECT_FLOAT_EQ(1.0f, m.a); + EXPECT_FLOAT_EQ(0.0f, m.b); + EXPECT_FLOAT_EQ(0.0f, m.c); + EXPECT_FLOAT_EQ(1.0f, m.d); + EXPECT_FLOAT_EQ(0.0f, m.e); + EXPECT_FLOAT_EQ(0.0f, m.f); EXPECT_TRUE(m.IsIdentity()); } +TEST(CFX_Matrix, AsTuple) { + CFX_Matrix m(1, 2, 3, 4, 5, 6); + auto tuple = m.AsTuple(); + EXPECT_FLOAT_EQ(1.0f, std::get<0>(tuple)); + EXPECT_FLOAT_EQ(2.0f, std::get<1>(tuple)); + EXPECT_FLOAT_EQ(3.0f, std::get<2>(tuple)); + EXPECT_FLOAT_EQ(4.0f, std::get<3>(tuple)); + EXPECT_FLOAT_EQ(5.0f, std::get<4>(tuple)); + EXPECT_FLOAT_EQ(6.0f, std::get<5>(tuple)); +} + TEST(CFX_Matrix, GetInverse) { static constexpr float data[6] = {3, 0, 2, 3, 1, 4}; CFX_Matrix m(data); -- cgit v1.2.3