summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/fx_coordinates.cpp24
-rw-r--r--core/fxcrt/fx_coordinates.h2
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp14
3 files changed, 18 insertions, 22 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 27c0a95ee4..0b6aed44cc 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -197,18 +197,20 @@ CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) {
return CFX_FloatRect(min_x, min_y, max_x, max_y);
}
-void CFX_Matrix::SetReverse(const CFX_Matrix& m) {
- float i = m.a * m.d - m.b * m.c;
+CFX_Matrix CFX_Matrix::GetInverse() const {
+ CFX_Matrix inverse;
+ float i = a * d - b * c;
if (fabs(i) == 0)
- return;
+ return inverse;
float j = -i;
- a = m.d / i;
- b = m.b / j;
- c = m.c / j;
- d = m.a / i;
- e = (m.c * m.f - m.d * m.e) / i;
- f = (m.a * m.f - m.b * m.e) / j;
+ inverse.a = d / i;
+ inverse.b = b / j;
+ inverse.c = c / j;
+ inverse.d = a / i;
+ inverse.e = (c * f - d * e) / i;
+ inverse.f = (a * f - b * e) / j;
+ return inverse;
}
void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) {
@@ -216,9 +218,7 @@ void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) {
}
void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, bool bPrepended) {
- CFX_Matrix m;
- m.SetReverse(src);
- Concat(m, bPrepended);
+ Concat(src.GetInverse(), bPrepended);
}
bool CFX_Matrix::Is90Rotated() const {
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index fc51c458a0..25923f7290 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -608,7 +608,7 @@ class CFX_Matrix {
f = 0;
}
- void SetReverse(const CFX_Matrix& m);
+ CFX_Matrix GetInverse() const;
void Concat(const CFX_Matrix& m, bool bPrepended = false);
void ConcatInverse(const CFX_Matrix& m, bool bPrepended = false);
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index 12ddb97330..e998b440f5 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -8,10 +8,9 @@
TEST(CFX_Matrix, ReverseIdentity) {
CFX_Matrix m;
- CFX_Matrix rev;
-
m.SetIdentity();
- rev.SetReverse(m);
+ CFX_Matrix rev = m.GetInverse();
+
EXPECT_FLOAT_EQ(1.0, rev.a);
EXPECT_FLOAT_EQ(0.0, rev.b);
EXPECT_FLOAT_EQ(0.0, rev.c);
@@ -28,9 +27,8 @@ TEST(CFX_Matrix, ReverseIdentity) {
TEST(CFX_Matrix, Reverse) {
float data[6] = {3, 0, 2, 3, 1, 4};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- rev.SetReverse(m);
EXPECT_FLOAT_EQ(0.33333334f, rev.a);
EXPECT_FLOAT_EQ(0.0f, rev.b);
EXPECT_FLOAT_EQ(-0.22222222f, rev.c);
@@ -50,9 +48,8 @@ TEST(CFX_Matrix, ReverseCR702041) {
float data[6] = {0.947368443f, -0.108947366f, -0.923076928f,
0.106153846f, 18.0f, 787.929993f};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- 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);
@@ -71,9 +68,8 @@ TEST(CFX_Matrix, ReverseCR714187) {
// The determinate is < std::numeric_limits<float>::epsilon()
float data[6] = {0.000037f, 0.0f, 0.0f, -0.000037f, 182.413101f, 136.977646f};
CFX_Matrix m(data);
- CFX_Matrix rev;
+ CFX_Matrix rev = m.GetInverse();
- rev.SetReverse(m);
EXPECT_FLOAT_EQ(27027.025f, rev.a);
EXPECT_FLOAT_EQ(0.0f, rev.b);
EXPECT_FLOAT_EQ(0.0f, rev.c);