Commit f938d8e5 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

More general test for TransformBetweenRects

The current test case for gfx::TransformBetweenRects only verifies
the function on the source rectangle whose origin is at (0,0).
This CL provides a more general test case.

Bug: 1046983
Change-Id: I06a451ce7bcbad1344139792d6265d5313fe782d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036272Reviewed-by: default avatarIan Vollick <vollick@chromium.org>
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739110}
parent 2e8cc3af
...@@ -320,13 +320,29 @@ TEST(TransformUtilTest, Transform2D) { ...@@ -320,13 +320,29 @@ TEST(TransformUtilTest, Transform2D) {
} }
TEST(TransformUtilTest, TransformBetweenRects) { TEST(TransformUtilTest, TransformBetweenRects) {
const RectF src_rect(0.f, 0.f, 5.f, 5.f); auto verify = [](const RectF& src_rect, const RectF& dst_rect) {
const RectF dst_rect(10.f, 10.f, 10.f, 20.f); const Transform transform = TransformBetweenRects(src_rect, dst_rect);
Transform transform = TransformBetweenRects(src_rect, dst_rect); // Applies |transform| to calculate the target rectangle from |src_rect|.
RectF transformed_rect = src_rect; // Notes that |transform| is in |src_rect|'s local coordinates.
transform.TransformRect(&transformed_rect); RectF dst_in_src_coordinates = RectF(src_rect.size());
EXPECT_EQ(dst_rect, transformed_rect); transform.TransformRect(&dst_in_src_coordinates);
RectF dst_in_parent_coordinates = dst_in_src_coordinates;
dst_in_parent_coordinates.Offset(src_rect.OffsetFromOrigin());
// Verifies that the target rectangle is expected.
EXPECT_EQ(dst_rect, dst_in_parent_coordinates);
};
std::vector<const std::pair<const RectF, const RectF>> test_cases{
{RectF(0.f, 0.f, 2.f, 3.f), RectF(3.f, 5.f, 4.f, 9.f)},
{RectF(10.f, 7.f, 2.f, 6.f), RectF(4.f, 2.f, 1.f, 12.f)},
{RectF(0.f, 0.f, 3.f, 5.f), RectF(0.f, 0.f, 6.f, 2.5f)}};
for (const auto& test_case : test_cases) {
verify(test_case.first, test_case.second);
verify(test_case.second, test_case.first);
}
} }
} // namespace } // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment