[Impeller] Add Rect::GetPositive (flutter/engine#35083)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user