Fix Rect::Compare bugs (flutter/engine#10)

This commit is contained in:
Brandon DeRosier
2022-02-16 11:53:49 -08:00
committed by Dan Field
parent bfdba8de0b
commit a7c10ebfab
2 changed files with 27 additions and 2 deletions

View File

@@ -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

View File

@@ -80,8 +80,8 @@ struct TRect {
}
constexpr bool Contains(const TPoint<Type>& 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(); }