codematrix
codematrix

Reputation: 1611

How to change Rectanlge Left/Top/Right/Bottom

I have two rectangles InnerRectangle and OuterRectangle. I want to verify if four corners of InnerRectangle i.e, Lett, Top, Right, Bottom are completely inside of OuterRectangle. If those are outside I want change the ones that are outside. If I change Left/Top/Right/Bottom, how much should I change the width or height? Please let me know how to implement this.

if (InnerRectangle.Left < OuterRectangle.Left)
{
    // what should I put here
}
if (InnerRectangle.Top < OuterRectangle.Top)
{
    // what should I put here
}
if (InnerRectangle.Right < OuterRectangle.Right)
{
    // what should I put here
}
if (InnerRectangle.Bottom < OuterRectangle.Bottom)
{
    // what should I put here
}

Appreciate your help..

Upvotes: 0

Views: 641

Answers (1)

Timwi
Timwi

Reputation: 66573

To check whether rectangle InnerRectangle is completely contained inside OuterRectangle:

if (OuterRectangle.Contains(InnerRectangle))
{
    // ...
}

To fix InnerRectangle so that it is really inside OuterRectangle:

InnerRectangle = InnerRectangle.Intersect(OuterRectangle);

Upvotes: 1

Related Questions