Skip to content

Commit ca3433d

Browse files
bderodnfield
authored andcommitted
Fix Rect::Compare bugs (#10)
1 parent 3d422b2 commit ca3433d

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

impeller/geometry/geometry_unittests.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,30 @@ TEST(GeometryTest, RectIntersection) {
310310
}
311311
}
312312

313+
TEST(GeometryTest, RectContainsPoint) {
314+
{
315+
// Origin is inclusive
316+
Rect r(100, 100, 100, 100);
317+
Point p(100, 100);
318+
ASSERT_TRUE(r.Contains(p));
319+
}
320+
{
321+
// Size is exclusive
322+
Rect r(100, 100, 100, 100);
323+
Point p(200, 200);
324+
ASSERT_FALSE(r.Contains(p));
325+
}
326+
{
327+
Rect r(100, 100, 100, 100);
328+
Point p(99, 99);
329+
ASSERT_FALSE(r.Contains(p));
330+
}
331+
{
332+
Rect r(100, 100, 100, 100);
333+
Point p(199, 199);
334+
ASSERT_TRUE(r.Contains(p));
335+
}
336+
}
337+
313338
} // namespace testing
314339
} // namespace impeller

impeller/geometry/rect.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ struct TRect {
8080
}
8181

8282
constexpr bool Contains(const TPoint<Type>& p) const {
83-
return p.x >= origin.x && p.x <= size.width && p.y >= origin.y &&
84-
p.y <= size.height;
83+
return p.x >= origin.x && p.x < origin.x + size.width && p.y >= origin.y &&
84+
p.y < origin.y + size.height;
8585
}
8686

8787
constexpr bool IsZero() const { return size.IsZero(); }

0 commit comments

Comments
 (0)