From 56004348c34be39522772c45f10f53c765b19084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tam=C3=A1s=20B=C3=A1lint=20Misius?= Date: Thu, 22 Jun 2023 21:39:09 +0200 Subject: [PATCH] Fix negative-size rects being returned by Rect::operator & Which make some sense in theory but they're prone to mishandling on usage sites, such as RasterDrawMethodsImpl.h:171. --- src/common/Vec2.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/common/Vec2.h b/src/common/Vec2.h index 7bbf896d1..c0ad17c5f 100644 --- a/src/common/Vec2.h +++ b/src/common/Vec2.h @@ -368,10 +368,17 @@ public: // Return the intersection of two rectangles (possibly empty) Rect operator&(Rect other) const { - return Rect( + auto rect = Rect( Vec2(std::max(TopLeft.X, other.TopLeft.X), std::max(TopLeft.Y, other.TopLeft.Y)), Vec2(std::min(BottomRight.X, other.BottomRight.X), std::min(BottomRight.Y, other.BottomRight.Y)) ); + return Rect( + rect.TopLeft, + Vec2( + std::max(rect.TopLeft.X - 1, rect.BottomRight.X), + std::max(rect.TopLeft.Y - 1, rect.BottomRight.Y) + ) + ); } inline Rect &operator|=(Rect other)