summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fxcrt/fx_coordinates.cpp82
-rw-r--r--core/fxcrt/fx_coordinates.h29
-rw-r--r--core/fxcrt/fx_coordinates_unittest.cpp70
3 files changed, 50 insertions, 131 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 13c6f1b6bc..12bf8b6c38 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -43,6 +43,15 @@ static_assert(sizeof(FX_RECT::bottom) == sizeof(RECT::bottom),
"FX_RECT vs. RECT mismatch");
#endif
+inline CFX_Matrix ConcatInternal(const CFX_Matrix& left,
+ const CFX_Matrix& right) {
+ return CFX_Matrix(
+ left.a * right.a + left.b * right.c, left.a * right.b + left.b * right.d,
+ left.c * right.a + left.d * right.c, left.c * right.b + left.d * right.d,
+ left.e * right.a + left.f * right.c + right.e,
+ left.e * right.b + left.f * right.d + right.f);
+}
+
} // namespace
void FX_RECT::Normalize() {
@@ -248,12 +257,20 @@ CFX_Matrix CFX_Matrix::GetInverse() const {
return inverse;
}
-void CFX_Matrix::Concat(const CFX_Matrix& m, bool bPrepended) {
- ConcatInternal(m, bPrepended);
+void CFX_Matrix::Concat(const CFX_Matrix& m) {
+ *this = ConcatInternal(*this, m);
+}
+
+void CFX_Matrix::ConcatPrepend(const CFX_Matrix& m) {
+ *this = ConcatInternal(m, *this);
+}
+
+void CFX_Matrix::ConcatInverse(const CFX_Matrix& src) {
+ Concat(src.GetInverse());
}
-void CFX_Matrix::ConcatInverse(const CFX_Matrix& src, bool bPrepended) {
- Concat(src.GetInverse(), bPrepended);
+void CFX_Matrix::ConcatInversePrepend(const CFX_Matrix& src) {
+ ConcatPrepend(src.GetInverse());
}
bool CFX_Matrix::Is90Rotated() const {
@@ -264,47 +281,33 @@ bool CFX_Matrix::IsScaled() const {
return fabs(b * 1000) < fabs(a) && fabs(c * 1000) < fabs(d);
}
-void CFX_Matrix::Translate(float x, float y, bool bPrepended) {
- if (bPrepended) {
- e += x * a + y * c;
- f += y * d + x * b;
- return;
- }
+void CFX_Matrix::Translate(float x, float y) {
e += x;
f += y;
}
-void CFX_Matrix::Scale(float sx, float sy, bool bPrepended) {
- a *= sx;
- d *= sy;
- if (bPrepended) {
- b *= sx;
- c *= sy;
- return;
- }
+void CFX_Matrix::TranslatePrepend(float x, float y) {
+ e += x * a + y * c;
+ f += y * d + x * b;
+}
+void CFX_Matrix::Scale(float sx, float sy) {
+ a *= sx;
b *= sy;
c *= sx;
+ d *= sy;
e *= sx;
f *= sy;
}
-void CFX_Matrix::Rotate(float fRadian, bool bPrepended) {
+void CFX_Matrix::Rotate(float fRadian) {
float cosValue = cos(fRadian);
float sinValue = sin(fRadian);
- ConcatInternal(CFX_Matrix(cosValue, sinValue, -sinValue, cosValue, 0, 0),
- bPrepended);
-}
-
-void CFX_Matrix::RotateAt(float fRadian, float x, float y, bool bPrepended) {
- Translate(-x, -y, bPrepended);
- Rotate(fRadian, bPrepended);
- Translate(x, y, bPrepended);
+ Concat(CFX_Matrix(cosValue, sinValue, -sinValue, cosValue, 0, 0));
}
-void CFX_Matrix::Shear(float fAlphaRadian, float fBetaRadian, bool bPrepended) {
- ConcatInternal(CFX_Matrix(1, tan(fAlphaRadian), tan(fBetaRadian), 1, 0, 0),
- bPrepended);
+void CFX_Matrix::Shear(float fAlphaRadian, float fBetaRadian) {
+ Concat(CFX_Matrix(1, tan(fAlphaRadian), tan(fBetaRadian), 1, 0, 0));
}
void CFX_Matrix::MatchRect(const CFX_FloatRect& dest,
@@ -396,22 +399,3 @@ CFX_FloatRect CFX_Matrix::TransformRect(const CFX_FloatRect& rect) const {
TransformRect(rect.left, rect.right, rect.top, rect.bottom);
return CFX_FloatRect(left, bottom, right, top);
}
-
-void CFX_Matrix::ConcatInternal(const CFX_Matrix& other, bool prepend) {
- CFX_Matrix left;
- CFX_Matrix right;
- if (prepend) {
- left = other;
- right = *this;
- } else {
- left = *this;
- right = other;
- }
-
- a = left.a * right.a + left.b * right.c;
- b = left.a * right.b + left.b * right.d;
- c = left.c * right.a + left.d * right.c;
- d = left.c * right.b + left.d * right.d;
- e = left.e * right.a + left.f * right.c + right.e;
- f = left.e * right.b + left.f * right.d + right.f;
-}
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 0b98ff2e43..f84c5ee220 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -592,8 +592,10 @@ class CFX_Matrix {
CFX_Matrix GetInverse() const;
- void Concat(const CFX_Matrix& m, bool bPrepended = false);
- void ConcatInverse(const CFX_Matrix& m, bool bPrepended = false);
+ void Concat(const CFX_Matrix& right);
+ void ConcatPrepend(const CFX_Matrix& left);
+ void ConcatInverse(const CFX_Matrix& m);
+ void ConcatInversePrepend(const CFX_Matrix& m);
bool IsIdentity() const {
return a == 1 && b == 0 && c == 0 && d == 1 && e == 0 && f == 0;
@@ -603,18 +605,18 @@ class CFX_Matrix {
bool IsScaled() const;
bool WillScale() const { return a != 1.0f || b != 0 || c != 0 || d != 1.0f; }
- void Translate(float x, float y, bool bPrepended = false);
- void Translate(int32_t x, int32_t y, bool bPrepended = false) {
- Translate(static_cast<float>(x), static_cast<float>(y), bPrepended);
+ void Translate(float x, float y);
+ void TranslatePrepend(float x, float y);
+ void Translate(int32_t x, int32_t y) {
+ Translate(static_cast<float>(x), static_cast<float>(y));
+ }
+ void TranslatePrepend(int32_t x, int32_t y) {
+ TranslatePrepend(static_cast<float>(x), static_cast<float>(y));
}
- void Scale(float sx, float sy, bool bPrepended = false);
- void Rotate(float fRadian, bool bPrepended = false);
-
- // Rotates counterclockwise around the (x, y) point.
- void RotateAt(float fRadian, float x, float y, bool bPrepended = false);
-
- void Shear(float fAlphaRadian, float fBetaRadian, bool bPrepended = false);
+ void Scale(float sx, float sy);
+ void Rotate(float fRadian);
+ void Shear(float fAlphaRadian, float fBetaRadian);
void MatchRect(const CFX_FloatRect& dest, const CFX_FloatRect& src);
@@ -641,9 +643,6 @@ class CFX_Matrix {
float d;
float e;
float f;
-
- private:
- void ConcatInternal(const CFX_Matrix& other, bool prepend);
};
#endif // CORE_FXCRT_FX_COORDINATES_H_
diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp
index d77fe05e91..b885d07095 100644
--- a/core/fxcrt/fx_coordinates_unittest.cpp
+++ b/core/fxcrt/fx_coordinates_unittest.cpp
@@ -437,9 +437,9 @@ TEST(CFX_Matrix, ComposeTransformations) {
// Now compose all transforms prepending.
m.SetIdentity();
- m.Concat(rotate_90, true);
- m.Concat(translate_23_11, true);
- m.Concat(scale_5_13, true);
+ m.ConcatPrepend(rotate_90);
+ m.ConcatPrepend(translate_23_11);
+ m.ConcatPrepend(scale_5_13);
EXPECT_NEAR_FIVE_PLACES(0.0f, m.a);
EXPECT_NEAR_FIVE_PLACES(5.0f, m.b);
EXPECT_NEAR_FIVE_PLACES(-13.0f, m.c);
@@ -458,67 +458,3 @@ TEST(CFX_Matrix, ComposeTransformations) {
EXPECT_FLOAT_EQ(-271.0f, p_10_20_transformed.x);
EXPECT_FLOAT_EQ(73.0f, p_10_20_transformed.y);
}
-
-TEST(CFX_Matrix, RotateAt) {
- CFX_Matrix m;
- m.RotateAt(FX_PI, 10, 20);
-
- // 180 degree rotation
- CFX_PointF p(27, 19);
- CFX_PointF new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(-7, new_p.x);
- EXPECT_FLOAT_EQ(21, new_p.y);
-
- p = CFX_PointF(10, 20);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(10, new_p.x);
- EXPECT_FLOAT_EQ(20, new_p.y);
-
- p = CFX_PointF(0, 0);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(20, new_p.x);
- EXPECT_FLOAT_EQ(40, new_p.y);
-
- // 90 degree rotation
- m.SetIdentity();
- m.RotateAt(FX_PI / 2, 10, 20);
-
- p = CFX_PointF(6, 17);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(13, new_p.x);
- EXPECT_FLOAT_EQ(16, new_p.y);
-
- p = CFX_PointF(10, 20);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(10, new_p.x);
- EXPECT_FLOAT_EQ(20, new_p.y);
-
- p = CFX_PointF(0, 0);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(30, new_p.x);
- EXPECT_FLOAT_EQ(10, new_p.y);
-
- // 60 degree rotation
- m.SetIdentity();
- m.RotateAt(FX_PI / 3, 10, 20);
-
- p = CFX_PointF(20, 20);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(15, new_p.x);
- EXPECT_FLOAT_EQ(28.660254f, new_p.y);
-
- p = CFX_PointF(10, 20);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(10, new_p.x);
- EXPECT_FLOAT_EQ(20, new_p.y);
-
- p = CFX_PointF(0, 0);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(22.320509f, new_p.x);
- EXPECT_FLOAT_EQ(1.3397465f, new_p.y);
-
- p = CFX_PointF(10, -80);
- new_p = m.Transform(p);
- EXPECT_FLOAT_EQ(96.602540f, new_p.x);
- EXPECT_FLOAT_EQ(-30, new_p.y);
-}