Mark CFX_Matrix ctors as constexpr, and delete test-only ctor
Delete the 1-param CFX_Matrix ctor that is only used in tests. Replace
it with calls to the 6-params ctor. Also mark the remaining ctors as
constexpr, and use that in the tests.
Change-Id: I77e09c897b598509a82997875eb0dc7696e6a191
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120490
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 49108ad..9b36865 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -451,12 +451,14 @@
//
class CFX_Matrix {
public:
- CFX_Matrix() = default;
+ constexpr CFX_Matrix() = default;
- explicit CFX_Matrix(const float n[6])
- : a(n[0]), b(n[1]), c(n[2]), d(n[3]), e(n[4]), f(n[5]) {}
-
- CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
+ constexpr CFX_Matrix(float a1,
+ float b1,
+ float c1,
+ float d1,
+ float e1,
+ float f1)
: a(a1), b(b1), c(c1), d(d1), e(e1), f(f1) {}
CFX_Matrix(const CFX_Matrix& other) = default;
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 3b05eab..0a9d863 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -395,8 +395,7 @@
}
TEST(CFX_Matrix, GetInverse) {
- static constexpr float data[6] = {3, 0, 2, 3, 1, 4};
- CFX_Matrix m(data);
+ constexpr CFX_Matrix m(3, 0, 2, 3, 1, 4);
CFX_Matrix rev = m.GetInverse();
EXPECT_FLOAT_EQ(0.33333334f, rev.a);
@@ -415,9 +414,8 @@
// Note, I think these are a bug and the matrix should be the identity.
TEST(CFX_Matrix, GetInverseCR702041) {
// The determinate is < std::numeric_limits<float>::epsilon()
- static constexpr float data[6] = {0.947368443f, -0.108947366f, -0.923076928f,
- 0.106153846f, 18.0f, 787.929993f};
- CFX_Matrix m(data);
+ constexpr CFX_Matrix m(0.947368443f, -0.108947366f, -0.923076928f,
+ 0.106153846f, 18.0f, 787.929993f);
CFX_Matrix rev = m.GetInverse();
EXPECT_FLOAT_EQ(14247728.0f, rev.a);
@@ -436,9 +434,8 @@
TEST(CFX_Matrix, GetInverseCR714187) {
// The determinate is < std::numeric_limits<float>::epsilon()
- static constexpr float data[6] = {0.000037f, 0.0f, 0.0f,
- -0.000037f, 182.413101f, 136.977646f};
- CFX_Matrix m(data);
+ constexpr CFX_Matrix m(0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f,
+ 136.977646f);
CFX_Matrix rev = m.GetInverse();
EXPECT_FLOAT_EQ(27027.025f, rev.a);