[Impeller] Add Rect::GetPositive (flutter/engine#35083)

This commit is contained in:
Brandon DeRosier
2022-08-02 15:07:23 -07:00
committed by GitHub
parent f428a1aa1f
commit f220d6ce4a
2 changed files with 22 additions and 0 deletions

View File

@@ -1049,6 +1049,20 @@ TEST(GeometryTest, RectMakePointBounds) {
}
}
TEST(GeometryTest, RectGetPositive) {
{
Rect r{100, 200, 300, 400};
auto actual = r.GetPositive();
ASSERT_RECT_NEAR(r, actual);
}
{
Rect r{100, 200, -100, -100};
auto actual = r.GetPositive();
Rect expected(0, 100, 100, 100);
ASSERT_RECT_NEAR(expected, actual);
}
}
TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
CubicPathComponent component({10, 10}, {20, 35}, {35, 20}, {40, 40});
SmoothingApproximation approximation;

View File

@@ -139,6 +139,14 @@ struct TRect {
return {left, top, right, bottom};
}
/// @brief Get a version of this rectangle that has a non-negative size.
constexpr TRect GetPositive() const {
auto ltrb = GetLTRB();
return MakeLTRB(ltrb[0], ltrb[1], ltrb[2], ltrb[3]);
}
/// @brief Get the points that represent the 4 corners of this rectangle. The
/// order is: Top left, top right, bottom left, bottom right.
constexpr std::array<TPoint<T>, 4> GetPoints() const {
auto [left, top, right, bottom] = GetLTRB();
return {TPoint(left, top), TPoint(right, top), TPoint(left, bottom),