[Impeller] Rect getters (flutter/engine#47411)

This is a precursor change that will allow us to migrate all of the Impeller sources off of accessing the `origin` and `size` fields in preparation for improving the implementation of `Rect`.

No code has been migrated to use the new fields yet, and so this code should be completely benign as is, but there will be a number of follow-on PRs that all share this PR as a pre-requisite and so it needs to be landed independently of any of the PRs that will modify code currently in use.
This commit is contained in:
Jim Graham
2023-10-27 19:24:10 -07:00
committed by GitHub
parent 86aada926d
commit 83db1b6e5f
4 changed files with 47 additions and 1 deletions

View File

@@ -141,6 +141,7 @@
../../../flutter/impeller/fixtures
../../../flutter/impeller/geometry/README.md
../../../flutter/impeller/geometry/geometry_unittests.cc
../../../flutter/impeller/geometry/rect_unittests.cc
../../../flutter/impeller/golden_tests/README.md
../../../flutter/impeller/golden_tests_harvester/.dart_tool
../../../flutter/impeller/golden_tests_harvester/.gitignore

View File

@@ -59,7 +59,11 @@ impeller_component("geometry_asserts") {
impeller_component("geometry_unittests") {
testonly = true
sources = [ "geometry_unittests.cc" ]
sources = [
"geometry_unittests.cc",
"rect_unittests.cc",
]
deps = [
":geometry",
":geometry_asserts",

View File

@@ -134,6 +134,20 @@ struct TRect {
constexpr bool IsMaximum() const { return *this == MakeMaximum(); }
/// @brief Returns the upper left corner of the rectangle as specified
/// when it was constructed.
///
/// Note that unlike the |GetLeft|, |GetTop|, and |GetLeftTop|
/// methods which will return values as if the rectangle had been
/// "unswapped" by calling |GetPositive| on it, this method
/// returns the raw origin values.
constexpr TPoint<Type> GetOrigin() const { return origin; }
/// @brief Returns the size of the rectangle as specified when it was
/// constructed and which may be negative in either width or
/// height.
constexpr TSize<Type> GetSize() const { return size; }
constexpr auto GetLeft() const {
if (IsMaximum()) {
return -std::numeric_limits<Type>::infinity();

View File

@@ -0,0 +1,27 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gtest/gtest.h"
#include "flutter/impeller/geometry/rect.h"
namespace impeller {
namespace testing {
TEST(RectTest, RectOriginSizeGetters) {
{
Rect r{{10, 20}, {50, 40}};
ASSERT_EQ(r.GetOrigin(), Point(10, 20));
ASSERT_EQ(r.GetSize(), Size(50, 40));
}
{
Rect r = Rect::MakeLTRB(10, 20, 50, 40);
ASSERT_EQ(r.GetOrigin(), Point(10, 20));
ASSERT_EQ(r.GetSize(), Size(40, 20));
}
}
} // namespace testing
} // namespace impeller