Shatterhand
2012-12-25 06:15:37
I want to make a function which will return true if two boxes cover each other. I would make TPAs from the boxes and use the FindTPAinTPA to get result. But I got some problems with the function.

The first problem is with the order. TPA1,TPA2 or TPA1,TPA2 -> its not the same. And according to Naum's tutorial FindTPAinTPA should not change the two input TPAs. As you can see on the second debug image, there is only one box there, one of the boxes (TPA) disappeared.
[PHP]{*******************************************************************************
function FindTPAinTPA(SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
Description: Looks for the TPA SearchTPA in the TPA TotalTPA and returns
the matched points to the TPA Matches. Returns true if there were atleast one
match(es).
*******************************************************************************} [/PHP]
The only way to make it work is to make the two TPAs again.
Box2 := IntToBox(0,0,50,50);
Box1 := IntToBox(25,25,75,75);
if BoxMatch(Box1,Box2) then
Writeln('True')
else
Writeln('False');
The first problem is with the order. TPA1,TPA2 or TPA1,TPA2 -> its not the same. And according to Naum's tutorial FindTPAinTPA should not change the two input TPAs. As you can see on the second debug image, there is only one box there, one of the boxes (TPA) disappeared.
[PHP]{*******************************************************************************
function FindTPAinTPA(SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
Description: Looks for the TPA SearchTPA in the TPA TotalTPA and returns
the matched points to the TPA Matches. Returns true if there were atleast one
match(es).
*******************************************************************************} [/PHP]
The only way to make it work is to make the two TPAs again.
function BoxMatch(Box1, Box2 : TBox): Boolean;
var
TPA1, TPA2, Matches : TPointArray;
begin
TPAFromBoxWrap(Box1,TPA1);
TPAFromBoxWrap(Box2,TPA2);
if FindTPAinTPA(TPA2,TPA1,Matches) then
begin
Result := True;
Exit;
end;
TPAFromBoxWrap(Box1,TPA1);
TPAFromBoxWrap(Box2,TPA2);
if FindTPAinTPA(TPA1,TPA2,Matches) then
begin
Result := True;
Exit;
end;
end;EDIT: It does not work at all! :(