Board index » delphi » Superposed TRect

Superposed TRect

Hi all,

How can I detect is 2 TRect are superposed (if they share the same screen
area)?

Is there something that is easier than calculate all the possibilities?

Thanks,

Martin

 

Re:Superposed TRect


I finally find something easy to do:

function InSameRegion(ASourceRect, ARect: TRect): boolean;
var
  VMaxRect: TRect;
begin
  // get the complete region
  VMaxRect.Left := Min(ASourceRect.Left, ARect.Left);
  VMaxRect.Right := Max(ASourceRect.Right, ARect.Right);
  VMaxRect.Top := Min(ASourceRect.Top, ARect.Top);
  VMaxRect.Bottom := Max(ASourceRect.Bottom, ARect.Bottom);
 // check if any overlap
  Result := (((ASourceRect.Right - ASourceRect.Left) + (ARect.Right -
ARect.Left)) >=
              (VMaxRect.Right - VMaxRect.Left)) and
            (((ASourceRect.Bottom - ASourceRect.Top) + (ARect.Bottom -
ARect.Top)) >=
              (VMaxRect.Bottom - VMaxRect.Top));

Seems to work!

Quote
Martin Simard <msim...@nospam.baan.com> wrote in message

news:s2r664iqhsq21@corp.supernews.com...
Quote
> Hi all,

> How can I detect is 2 TRect are superposed (if they share the same screen
> area)?

> Is there something that is easier than calculate all the possibilities?

> Thanks,

> Martin

Other Threads