dank BenBEs zutun, hab ich jetzt das hier:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| function RectRectIntersect(A, B: TRect; var C: TRect): boolean; begin Result := (A.Left <= B.Right) and (A.Right >= B.Left) and (A.Top <= B.Bottom) and (A.Bottom >= B.Top);
if Result = true then with C do begin Left := Min(A.Right, B.Left); Top := Min(A.Top, B.Bottom); Right := Max(B.Left, A.Right); Bottom := Max(B.Bottom, A.Top); end; end; |
ich musste aber seine version ein wenig anpassen damit das für mein beispiel so klappt, ich bin mir aber nicht sicher, ob das allgemeingültig ist und für beide fälle funzt:
benbes version sah so aus:
Delphi-Quelltext
1: 2: 3: 4:
| C.Left := Min ( A.Right, B.Left ); C.Top := Min ( A.Bottom, B. Top ); C.Right := Max ( A.Left, B.Right ); C.Bottom := Max ( A.Top, B. Bottom ); |
EDIT: ich denke so gehts (hatte mich im koordinatensystem geirrt):
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| function RectRectIntersect(A, B: TRect; var C: TRect): boolean; begin Result := (A.Left <= B.Right) and (A.Right >= B.Left) and (A.Top <= B.Bottom) and (A.Bottom >= B.Top);
if Result = true then with C do begin Left := Min(A.Right, B.Left); Top := Min(A.Top, B.Bottom); Right := Max(B.Left, A.Right); Bottom := Max(B.Bottom, A.Top); end; end; |
mfg