From d671ae4a1182c794d9f0ae760f6a3401caf4234d Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 20 Dec 2023 11:14:02 -0800 Subject: [PATCH] [Impeller] fixed Rect::Contains --- impeller/geometry/rect.h | 3 ++- impeller/geometry/rect_unittests.cc | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/impeller/geometry/rect.h b/impeller/geometry/rect.h index 2ec405b6e165f..637f3ce5250e0 100644 --- a/impeller/geometry/rect.h +++ b/impeller/geometry/rect.h @@ -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. diff --git a/impeller/geometry/rect_unittests.cc b/impeller/geometry/rect_unittests.cc index 54a5f163ce3de..a7611acacf57c 100644 --- a/impeller/geometry/rect_unittests.cc +++ b/impeller/geometry/rect_unittests.cc @@ -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