Skip to content

Commit

Permalink
Fix Rect::Compare bugs (flutter#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent 3d422b2 commit ca3433d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions impeller/geometry/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down

0 comments on commit ca3433d

Please sign in to comment.