public void Intersect(Rect rect)
{
if (!this.IntersectsWith(rect))
{
this = s_empty;
}
else
{
double left = Math.Max(X, rect.X);
double top = Math.Max(Y, rect.Y);
// Max with 0 to prevent double weirdness from causing us to be (-epsilon..0)
Width = Math.Max(Math.Min(X + Width, rect.X + rect.Width) - left, 0);
Height = Math.Max(Math.Min(Y + Height, rect.Y + rect.Height) - top, 0);
X = left;
Y = top;
}
}