diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-18 20:39:02 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-18 20:39:02 +0000 |
commit | 4754adaf70d8708610ea31a4d5e3df7c4fcb2ef0 (patch) | |
tree | 03a9641804ec0c796fc3447b07c423ae6059f171 | |
parent | 70156345b2a7bc57b8bfca5f3d58c34505ad6518 (diff) | |
download | pdfium-4754adaf70d8708610ea31a4d5e3df7c4fcb2ef0.tar.xz |
Add unit tests for CFX_Matrix::TransformRect().
Change-Id: Id4bebae05116422b15019e7b972f5e8594317afe
Reviewed-on: https://pdfium-review.googlesource.com/c/43949
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
-rw-r--r-- | core/fxcrt/fx_coordinates.h | 6 | ||||
-rw-r--r-- | core/fxcrt/fx_coordinates_unittest.cpp | 42 |
2 files changed, 48 insertions, 0 deletions
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h index d01191da37..4a63a6ca37 100644 --- a/core/fxcrt/fx_coordinates.h +++ b/core/fxcrt/fx_coordinates.h @@ -274,6 +274,10 @@ class CFX_FloatRect { float Width() const { return right - left; } float Height() const { return top - bottom; } + float Left() const { return left; } + float Bottom() const { return bottom; } + float Right() const { return right; } + float Top() const { return top; } void Inflate(float x, float y); void Inflate(float other_left, @@ -426,6 +430,8 @@ class CFX_RectF { return rt.left >= left && rt.right() <= right() && rt.top >= top && rt.bottom() <= bottom(); } + float Left() const { return left; } + float Top() const { return top; } float Width() const { return width; } float Height() const { return height; } SizeType Size() const { return SizeType(width, height); } diff --git a/core/fxcrt/fx_coordinates_unittest.cpp b/core/fxcrt/fx_coordinates_unittest.cpp index b885d07095..3d11748649 100644 --- a/core/fxcrt/fx_coordinates_unittest.cpp +++ b/core/fxcrt/fx_coordinates_unittest.cpp @@ -458,3 +458,45 @@ 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, TransformRectForRectF) { + CFX_Matrix rotate_90; + rotate_90.Rotate(FX_PI / 2); + + CFX_Matrix scale_5_13; + scale_5_13.Scale(5, 13); + + CFX_RectF rect(10.5f, 20.5f, 4.25f, 3.25f); + rect = rotate_90.TransformRect(rect); + EXPECT_FLOAT_EQ(-23.75f, rect.Left()); + EXPECT_FLOAT_EQ(10.5f, rect.Top()); + EXPECT_FLOAT_EQ(3.25f, rect.Width()); + EXPECT_FLOAT_EQ(4.25f, rect.Height()); + + rect = scale_5_13.TransformRect(rect); + EXPECT_FLOAT_EQ(-118.75f, rect.Left()); + EXPECT_FLOAT_EQ(136.5f, rect.Top()); + EXPECT_FLOAT_EQ(16.25f, rect.Width()); + EXPECT_FLOAT_EQ(55.25f, rect.Height()); +} + +TEST(CFX_Matrix, TransformRectForFloatRect) { + CFX_Matrix rotate_90; + rotate_90.Rotate(FX_PI / 2); + + CFX_Matrix scale_5_13; + scale_5_13.Scale(5, 13); + + CFX_FloatRect rect(5.5f, 0.0f, 12.25f, 2.7f); + rect = rotate_90.TransformRect(rect); + EXPECT_FLOAT_EQ(-2.7f, rect.Left()); + EXPECT_FLOAT_EQ(5.5f, rect.Bottom()); + EXPECT_NEAR(0.0f, rect.Right(), 0.00001f); + EXPECT_FLOAT_EQ(12.25f, rect.Top()); + + rect = scale_5_13.TransformRect(rect); + EXPECT_FLOAT_EQ(-13.5f, rect.Left()); + EXPECT_FLOAT_EQ(71.5f, rect.Bottom()); + EXPECT_NEAR(0.0f, rect.Right(), 0.00001f); + EXPECT_FLOAT_EQ(159.25f, rect.Top()); +} |