Skip to content

Commit c041987

Browse files
committed
fix: Rectangle.Intersect
1 parent a68c4a4 commit c041987

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/Rectangle.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,16 @@ public static void Intersect(
397397
ref Rectangle value2,
398398
out Rectangle result
399399
) {
400-
int right1 = value1.X + value1.Width; // inline value1.Right
401-
int right2 = value2.X + value2.Width; // inline value2.Right
402-
int bottom1 = value1.Y + value1.Height; // inline value1.Bottom
403-
int bottom2 = value2.Y + value2.Height; // inline value2.Bottom
404-
if (value1.X < right2 && value2.X < right1 && value1.Y < bottom2 && value2.Y < bottom1)
400+
int right = Math.Min(value1.Right, value2.Right);
401+
int bottom = Math.Min(value1.Bottom, value2.Bottom);
402+
int left = Math.Max(value1.Left, value2.Left);
403+
int top = Math.Max(value1.Top, value2.Top);
404+
if (left < right && top < bottom)
405405
{
406-
result.X = Math.Max(value1.X, value2.X);
407-
result.Y = Math.Max(value1.Y, value2.Y);
408-
result.Width = Math.Min(right1, right2) - result.X;
409-
result.Height = Math.Min(bottom1, bottom2) - result.Y;
406+
result.X = left;
407+
result.Y = top;
408+
result.Width = right - left;
409+
result.Height = bottom - top;
410410
}
411411
else
412412
{

0 commit comments

Comments
 (0)