Missing Rectangle.Intersects

Apr 1, 2009 at 11:21 PM
Edited Apr 1, 2009 at 11:22 PM
Hello,

I saw that Rectangle.Intersects was missing, so I created an extension method :

public static bool Intersects(this Rectangle rectangle, Rectangle rectangle2)
{
    Rect rect = new Rect
    {
        X = rectangle.X,
        Y = rectangle.Y,
        Width = rectangle.Width,
        Height = rectangle.Height    
    };
    Rect rect2 = new Rect
    {
        X = rectangle2.X,
        Y = rectangle2.Y,
        Width = rectangle2.Width,
        Height = rectangle2.Height
    };

    rect.Intersect(rect2);

    return !(rect == Rect.Empty);
}

Feel free to re-use it if it's correct.

Thanks for your project.

If you need some help, feel free to contact me :)

Benjamin Roux [MVP Client App Dev]
Coordinator
Apr 2, 2009 at 5:16 PM
Benjamin,

Thanks, I have a good rectangle intersects method around somewhere, I'll add this as an issue and implement it.

Bill