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.
This commit is contained in:
Tamás Bálint Misius 2023-06-22 21:39:09 +02:00
parent 2bc2acc00e
commit 56004348c3
No known key found for this signature in database
GPG Key ID: 5B472A12F6ECA9F2

View File

@ -368,10 +368,17 @@ public:
// Return the intersection of two rectangles (possibly empty) // Return the intersection of two rectangles (possibly empty)
Rect<T> operator&(Rect<T> other) const Rect<T> operator&(Rect<T> other) const
{ {
return Rect<T>( auto rect = Rect<T>(
Vec2<T>(std::max(TopLeft.X, other.TopLeft.X), std::max(TopLeft.Y, other.TopLeft.Y)), Vec2<T>(std::max(TopLeft.X, other.TopLeft.X), std::max(TopLeft.Y, other.TopLeft.Y)),
Vec2<T>(std::min(BottomRight.X, other.BottomRight.X), std::min(BottomRight.Y, other.BottomRight.Y)) Vec2<T>(std::min(BottomRight.X, other.BottomRight.X), std::min(BottomRight.Y, other.BottomRight.Y))
); );
return Rect<T>(
rect.TopLeft,
Vec2<T>(
std::max(rect.TopLeft.X - 1, rect.BottomRight.X),
std::max(rect.TopLeft.Y - 1, rect.BottomRight.Y)
)
);
} }
inline Rect<T> &operator|=(Rect<T> other) inline Rect<T> &operator|=(Rect<T> other)