[Impeller] fixed Rect::Contains (flutter/engine#49294)

fixes https://github.com/flutter/flutter/issues/140464

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke
2023-12-20 14:31:02 -08:00
committed by GitHub
parent 31dd800cac
commit ff7148c8c2
2 changed files with 9 additions and 1 deletions

View File

@@ -130,7 +130,8 @@ struct TRect {
}
[[nodiscard]] constexpr bool Contains(const TRect& o) const {
return Union(o).size == size;
return o.GetLeft() >= GetLeft() && o.GetTop() >= GetTop() &&
o.GetRight() <= GetRight() && o.GetBottom() <= GetBottom();
}
/// Returns true if either of the width or height are 0, negative, or NaN.

View File

@@ -492,5 +492,12 @@ TEST(RectTest, IRectExpand) {
EXPECT_EQ(rect.Expand(ISize{-10, -10}), IRect::MakeLTRB(110, 110, 190, 190));
}
TEST(RectTest, ContainsFloatingPoint) {
auto rect1 =
Rect::MakeXYWH(472.599945f, 440.999969f, 1102.80005f, 654.000061f);
auto rect2 = Rect::MakeXYWH(724.f, 618.f, 600.f, 300.f);
EXPECT_TRUE(rect1.Contains(rect2));
}
} // namespace testing
} // namespace impeller