diff --git a/engine/src/flutter/impeller/geometry/geometry_unittests.cc b/engine/src/flutter/impeller/geometry/geometry_unittests.cc index fdd3613369..a567475c78 100644 --- a/engine/src/flutter/impeller/geometry/geometry_unittests.cc +++ b/engine/src/flutter/impeller/geometry/geometry_unittests.cc @@ -310,5 +310,30 @@ TEST(GeometryTest, RectIntersection) { } } +TEST(GeometryTest, RectContainsPoint) { + { + // Origin is inclusive + Rect r(100, 100, 100, 100); + Point p(100, 100); + ASSERT_TRUE(r.Contains(p)); + } + { + // Size is exclusive + Rect r(100, 100, 100, 100); + Point p(200, 200); + ASSERT_FALSE(r.Contains(p)); + } + { + Rect r(100, 100, 100, 100); + Point p(99, 99); + ASSERT_FALSE(r.Contains(p)); + } + { + Rect r(100, 100, 100, 100); + Point p(199, 199); + ASSERT_TRUE(r.Contains(p)); + } +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/geometry/rect.h b/engine/src/flutter/impeller/geometry/rect.h index 4517eba06e..00a0ae6ddd 100644 --- a/engine/src/flutter/impeller/geometry/rect.h +++ b/engine/src/flutter/impeller/geometry/rect.h @@ -80,8 +80,8 @@ struct TRect { } constexpr bool Contains(const TPoint& p) const { - return p.x >= origin.x && p.x <= size.width && p.y >= origin.y && - p.y <= size.height; + return p.x >= origin.x && p.x < origin.x + size.width && p.y >= origin.y && + p.y < origin.y + size.height; } constexpr bool IsZero() const { return size.IsZero(); }