Algorithm for finding a rectangle constrained to its parent

Posted by Milo on Stack Overflow See other posts from Stack Overflow or by Milo
Published on 2011-01-01T01:07:25Z Indexed on 2011/01/01 1:54 UTC
Read the original article Hit count: 511

Filed under:
|
|

Basically what I want to do is illustrated here: alt text

I start with A and B, then B is conformed to A to create C.

The idea is, given TLBR rectangles A, B, make C

I also need to know if it produces an empty rectangle (B outside of A case).

I tried this but it just isn't doing what I want:

if(clipRect.getLeft() > rect.getLeft())
    L = clipRect.getLeft();
else
    L = rect.getLeft();

if(clipRect.getRight() < rect.getRight())
    R = clipRect.getRight();
else
    R = rect.getRight();

if(clipRect.getBottom() > rect.getBottom())
    B = clipRect.getBottom();
else
    B = rect.getBottom();

if(clipRect.getTop() < rect.getTop())
    T = clipRect.getTop();
else
    T = rect.getTop();

if(L < R && B < T)
{
    clipRect = AguiRectangle(0,0,0,0);
}
else
{
    clipRect = AguiRectangle::fromTLBR(T,L,B,R);
}

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about rectangle