Autor Beitrag
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Fr 04.08.06 19:18 
dank BenBEs zutun, hab ich jetzt das hier:
ausblenden 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:

user defined image

benbes version sah so aus:
ausblenden 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):
ausblenden 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